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.
| Author |
Topic |
|
haribabu.rk
Starting Member
2 Posts |
Posted - 2008-08-30 : 00:30:39
|
| HiI wrote a Query likeselect * from emp where empid IN (3,16,19,2,15,4,7,1.......)which produces the Output in the sorted order like 1,2,3,4,7,15,16,19..... But I want the Output as in the order which I've mentioned after 'IN' operator.Actually I am sending a Comma Separated Values of Id's string from my front end to SqlServer and appending that string after 'IN' operator.Is there any way to get the output as I needed?Regards,Hari |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
Posted - 2008-08-30 : 00:54:30
|
| Your order appears to be meaningless. You'll need to insert the CSV list into a temporary table and put an identity column on it. You could then do this:SELECT *FROM emp eINNER JOIN #temp tON e.empid = t.empidORDER BY t.TempIdTara KizerMicrosoft MVP for Windows Server System - SQL Serverhttp://weblogs.sqlteam.com/tarad/Subscribe to my blog |
 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
|
|
|
|
|
|
|