UNPIVOT will not return NULLs, but I need them in a comparison query. I am trying to avoid using ISNULL the following example (Because in the real sql there are over 100 fields.:
Select ID, theValue, column_name
From
(select ID,
ISNULL(CAST([TheColumnToCompare] AS VarChar(1000)), '') as TheColumnToCompare
from MyView
where The_Date = '04/30/2009'
) MA
UNPIVOT
(theValue FOR column_name IN
([TheColumnToCompare])
) AS unpvt
Any alternatives?
I Run into the same problem, Using CROSS APPLY (Sql Server 2005 and Later) Instead of Unpivot Solved the problem. I found the solution Based on this Article An Alternative (Better?) Method to UNPIVOT and i made the following example to demonstrate that CROSS APPLY will NOT Ignore Nulls like Unpivot .