Site Sponsored By: SQLDSC - SQL Server Desired State Configuration
Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
I have this problem that is hard for me to describe (as well as search the web) so please bear with me on this one :-)I'm running a query that bring some IDs, I need the data to come back in the same order as it was requested, here's my query:
SELECT id, title FROM myTable WHERE id IN (5,8,65,32);
So sorted results should appear as the input, i.e. 5,8,65,32How should I approach this?
visakh16
Very Important crosS Applying yaK Herder
52326 Posts
Posted - 2008-10-06 : 23:56:16
[code]SELECT id, title FROM myTable WHERE id IN (5,8,65,32)ORDER BY CASE WHEN id=5 THEN 1 WHEN id=8 THEN 2 WHEN id=65 THEN 3 WHEN id=32 THEN 4 END[/code]