Click here to Skip to main content
15,886,919 members
Articles / Database Development / SQL Server
Alternative
Tip/Trick

CASE/WHEN return type

Rate me:
Please Sign up or sign in to vote.
0.00/5 (No votes)
24 Nov 2010CPOL 5.7K   1   2
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:

SQL
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.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Norway Norway
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
GeneralOh, I see that the OP's code is fine (I was not familiar wit... Pin
AspDotNetDev13-Dec-10 7:30
protectorAspDotNetDev13-Dec-10 7:30 
GeneralWhat do you mean by "append the sanitized column name to sor... Pin
AspDotNetDev13-Dec-10 7:21
protectorAspDotNetDev13-Dec-10 7:21 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.