last day (14 days later) » 

4:31 PM
1
A: SQL dynamic column names based on event order

John CappellettiIf SQL Server. You can use the window function ROW_NUMBER() to get the distinct Run Numbers, and then we simply run a dynamic pivot for the final results Declare @SQL varchar(max) Select @SQL = Stuff((Select Distinct ',' + QuoteName('Run'+cast(RN as varchar(25))) From (Select Distinct RN=Row_...

 
This is perfect! Thank you, I was not even looking at a XML PATH solution to build the column names. I guess I will need to look into this a bit more. Thank you John Cappelletti you saved my sanity.
 
@S.G. Happy to help. Looking into XML Path and the window functions is well worth the effort. Cheers :)
 
Any chance you know the best way to keep the columns for "Run<xx>" in order? To prevent the "Run1" "Run10" from happening? Also keeping "NULL" values with the actual run and not being pushed to the end?
 
@S.G. Just add the Order by in the 1st select ...) A Order by 1 For XML Path(...
@S.G. Updated answer just in case my comment was not clear
 
I cant get the XML output to be in order with that. I thought my "where" addition was breaking it but still no dice: code Stuff( (Select Distinct ',' + QuoteName('Run'+cast(RN as varchar(25))) From ( Select Distinct RN=Row_Number() over (Partition By RN_TEST_ID Order By RN_RUN_ID) from td.RUN where RN_CYCLE_ID = 501) A Order by 1 For XML Path('')),1,1,'') code
 
4:31 PM
@S.G. back at my desk. Give me a moment
@S.G. See code below "Edit"
@S.G. If you post a better/more robust sample of data I can help you drag this over the finish line.... Also, you may have to add the WHERE to you sub-query in the Pivot
 
Your the man! That first "DISTINCT" was breaking it, I never would have guessed that. I was trying to give the row an alias and then use a order by cast(substring(runName,4,3) as INT) to try and sort based on the isolated RN but was getting no where. Thanks a million. Now I just have to figure out why a null run gets pushed to the end (If Run 3 didnt do a Test ID, run 4 for that test ID falls in run 3's column) I'll find it! Eventually :)
 
@S.G. Well done then!
How can I help
 
Sorry I got the "This isnt a chat feed popup" didnt know that was a thing.
So I added Value=ISNULL(RN_Status,''NotRun'') to the 2nd @sql build in the hopes it would not leave the NULL runs behind but that is not the ans
I thought the PIVOT (Max(Value) For Item in ... needed to have "Something" in the status to keep it with the run
But not the case
 
You can upload an image of your results. This will help me visualize it better
 
O I think I know the problem
HOw do I paste in this thing
 
4:37 PM
Click on the upload button next to where you type
 
HA, Chrome is only showing me a send button
Well the issue is the data for a test that isnt run does not show in the result set
 
Huh. I'm on chrome
 
So Run ID 1 runs tests 1-5, then Run Id 2 only runs 1-4
Run 3 runs 1-5 again
BUT
The Run status for the missing run2 test 5 does not exist in the run set
 
Yeah I dont have one of those
 
4:41 PM
I'm a little confused. Do yo want a standard number of columns?
 
Well I should only have columns for each run, which you have laid out nicely
The issue is with how I get to that data
 
on a call . give me a moment
OK I'm back
 
For a run that didnt actually execute a test in that given run, there is no record of it to associate to for the test and run. I have a Run ID, a Test ID and the Test ID will only show for a RunID if it actually executed in some fashion. So my records are missing for non executed tests, but by design
I dont think I can get around this easily
So if all expected runs have 10 tests possible, meaning there are at most 10
 
I think I'm catching up to you
hold on
 
There are times not all 10 run, but I would have to build the table one run at a time based on expectation of all 10 being there
Sorry just thinking this through
If a test is missing from my runs, meaning the run id doesnt have a test id in the list of its last run then I have to assume its "Not Run" and add a placeholder status for that run and test combination, then check the next run
Does that logic path sound right?
 
4:56 PM
Still a little trouble with the visual. can you paste in some more sample data
 
I will have to load it to the post, this chat is missing the upload button for me for some reason
I have a meeting in 3 min but should be out by 2, hopefully I can get it to you while in the meeting if not I will have to send it after
 
OK ping me then
 
Thanks for all your help, my appreciated
much*
 
No worries I did the puzzles
 
If your familure with HP ALM then that is where all this is stemming from
I will get some data for you asap ttyl
 
 
2 hours later…
7:19 PM
Sorry things went long
I have a data file but no way to upload it to chat that I can see
 
7:38 PM
@JohnCappelletti I think I am going to need to include more links to at least one if not 2 tables to make this work
 
8:01 PM
If it helps, you can use my gmail john.m.cappelletti@gmail. All info will be 100% confidential.
 
There is nothing of a sensitive nature in the file so I am not concerned with that. I think I will need to reference another table that holds all the tests in a set that are expected to run and then populate status based on the given run
 
I trust your judgment, but you have me at a disadvantage. You know your data better than I ever could.
 
Okay I sent you 3 files
 
Got your email! give me a few minutes
 
I put descriptions as to what each represent and hopefully you can see what I am talking about :)
Not to disrupt but what I am thinking is, I need a list of all the tests (79 as you will see) then for each run 1st to last populate the status for all tests that occurred in that run. If there is not a match between test Id from the "Order List" and the Run ID being considered, its flagged as "Not Run"
Then move to the next run to fill the table for all runs
 
8:25 PM
Seems reasonable. I have 30 minutes until my next call. I'll see what I can slip in
 
Thank you for taking the time, it means a lot
 
8:54 PM
The issue I seem to be having is what to key on in the data. The last 4 columns should hold the data that corresponds to the actual run set being triggered. Specifically RN_PC_RESESRVATION_ID that is directly related to the automated run. The inconsistency is the few NULLS you'll see in that column that coincidentally with have matching columns for RN_PC_PROCEDURE_ID and PROCEDURE_NAME
 

last day (14 days later) »