Our client wants to see the type of test being examined in output. That is, instead of a column heading of “Results”, they want to see “Results for LAB TEST.” Could have been worse – they might have wanted “Results for LAB TEST in UNITS.” But we already return a column labeled “units” i guess this is not a real issue.
So the lab data is queried by test name, and it comes back without that name being in the result set. I gcuess we could add that column – which would then be the same for all the 100 or more rows, but instead i create a table, with a column ‘results’, populate the table with data, then rename the results column to include the lab name. Looks like this:
declare @name varchar(40) = 'result for ''' + @lab + '''' Execute tempdb..sp_rename '[tempdb].[dbo].[##intermediateResults].[result]', @name2,'column';
Declare a variable for the new name and construct it from the string and the name of the lab. Pass it to an instance of tempdb..sp_rename with the FQ table name with column, the name of the new column name, and the hint that we want to work on ‘columns’.