ifthenelsenull
Technical User
I am pivoting a temp table and the table is fine with no nulls or additional values but when I pivot the data gets split in half and I end up with nulls where there should be values. Instead of 1 row with 20 columns I get two rows with 20 columns with half the values in the top row and half in the bottom row.
The pivot looks like :
<code>
SELECT 'TOP_VALUE' AS New_VALUE,
[Wnd],
[ Type1 ],
[ Type8 ],
[ Type7 ],
[ Type6 ],
[ Type5 ],
[ Type4 ],
[ Type3 ],
[ Type2 ],
[ Stg1 ],
[ Stg2 ],
[ Stg3 ],
[ Stg4 ],
[ Stg5 ],
[ Stg6 ],
[ Stg7 ],
[ Stg8 ],
[Score ],
[SknRisk ]
FROM
(SELECT *
FROM #tbla0data
) AS SourceTable
PIVOT
(
MIN(VALUE)
FOR findingabbr IN (
[wnd],
[ Type1 ],
[ Type8 ],
[ Type7 ],
[ Type6 ],
[ Type5 ],
[ Type4 ],
[ Type3 ],
[ Type2 ],
[ Stg1 ],
[ Stg2 ],
[ Stg3 ],
[ Stg4 ],
[ Stg5 ],
[ Stg6 ],
[ Stg7 ],
[ Stg8 ],
[A_BradenScore ],
[D_N_SknRisk ])
) AS PivotTable;
-- FIRST ATTEMPT I thought this might just be missing something
--select DISTINCT * from #tbla0data
--pivot (MAX(value) for findingabbr IN(
--[D_N_noWnd],
--[ Type1 ],
--[ Type8 ],
--[ Type7 ],
--[ Type6 ],
--[ Type5 ],
--[ Type4 ],
--[ Type3 ],
--[ Type2 ],
--[ Stg1 ],
--[ Stg2 ],
--[ Stg3 ],
--[ Stg4 ],
--[ Stg5 ],
--[ Stg6 ],
--[ Stg7 ],
--[ Stg8 ],
--[Score ],
--[Risk ])) as maxvalue
</code>
The pivot looks like :
<code>
SELECT 'TOP_VALUE' AS New_VALUE,
[Wnd],
[ Type1 ],
[ Type8 ],
[ Type7 ],
[ Type6 ],
[ Type5 ],
[ Type4 ],
[ Type3 ],
[ Type2 ],
[ Stg1 ],
[ Stg2 ],
[ Stg3 ],
[ Stg4 ],
[ Stg5 ],
[ Stg6 ],
[ Stg7 ],
[ Stg8 ],
[Score ],
[SknRisk ]
FROM
(SELECT *
FROM #tbla0data
) AS SourceTable
PIVOT
(
MIN(VALUE)
FOR findingabbr IN (
[wnd],
[ Type1 ],
[ Type8 ],
[ Type7 ],
[ Type6 ],
[ Type5 ],
[ Type4 ],
[ Type3 ],
[ Type2 ],
[ Stg1 ],
[ Stg2 ],
[ Stg3 ],
[ Stg4 ],
[ Stg5 ],
[ Stg6 ],
[ Stg7 ],
[ Stg8 ],
[A_BradenScore ],
[D_N_SknRisk ])
) AS PivotTable;
-- FIRST ATTEMPT I thought this might just be missing something
--select DISTINCT * from #tbla0data
--pivot (MAX(value) for findingabbr IN(
--[D_N_noWnd],
--[ Type1 ],
--[ Type8 ],
--[ Type7 ],
--[ Type6 ],
--[ Type5 ],
--[ Type4 ],
--[ Type3 ],
--[ Type2 ],
--[ Stg1 ],
--[ Stg2 ],
--[ Stg3 ],
--[ Stg4 ],
--[ Stg5 ],
--[ Stg6 ],
--[ Stg7 ],
--[ Stg8 ],
--[Score ],
--[Risk ])) as maxvalue
</code>