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 |
|
vipinspg
Starting Member
12 Posts |
Posted - 2005-07-06 : 08:08:14
|
| Hi AllSuppose we have a table named employee with columns empid and empname. Also we are having a string containing comma separated emp ids. My requirement is we need to fetch employee records in the same order of ids as in the string. For example, if the string contains '2,1,5', then we need to get employee records with empid having 2 should come first, then record with empid 1 and finally the record with empid 5. Can anyone suggest a solution for this ?Thanks in advance for your time.ThanksVipins. |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2005-07-06 : 08:47:04
|
| [code]select columns from yourtable order by case when col=2 then 1 when col=1 then 2 when col=5 then 3 end[/code]MadhivananFailing to plan is Planning to fail |
 |
|
|
AndrewMurphy
Master Smack Fu Yak Hacker
2916 Posts |
Posted - 2005-07-06 : 09:19:35
|
| This works when the order is hardcoded.....but I suspect the poster intends the "csv list" to be a parameter, in which case the order is relative to the start of the csv list. |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2005-07-06 : 09:28:43
|
| In that case I dont think it will be done through dynamic Order byMadhivananFailing to plan is Planning to fail |
 |
|
|
vipinspg
Starting Member
12 Posts |
Posted - 2005-07-07 : 03:06:31
|
| Hi madhivananThanks for your answer. This is what I was expecting. Thanks a lot.Vipins. |
 |
|
|
|
|
|