65.9K
CodeProject is changing. Read more.
Home

CASE/WHEN return type

emptyStarIconemptyStarIconemptyStarIconemptyStarIconemptyStarIcon

0/5 (0 vote)

Nov 24, 2010

CPOL
viewsIcon

6028

Unless you are placing this code in a stored procedure, you could just as well do this:SELECT *FROM ( SELECT 'A1' AS String1,'B1' AS String2, GETDATE() AS DateCol UNION ALL SELECT 'A2','B2', GETDATE()) AS dORDER BY And then append the sanitized column name to sort...

Unless you are placing this code in a stored procedure, you could just as well do this:
SELECT *
FROM (
   SELECT 'A1' AS String1,'B1' AS String2, GETDATE() AS DateCol
   UNION ALL
   SELECT 'A2','B2', GETDATE()
)  AS d
ORDER BY 
And then append the sanitized column name to sort by before executing it.