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 |
|
boreddy
Posting Yak Master
172 Posts |
Posted - 2008-08-27 : 03:24:19
|
| I have a table called emp with ID's 1 to 20I wrote a Query to get the emp details 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. |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2008-08-27 : 03:28:12
|
quote: Originally posted by madhivanan Duplicate of http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=109561MadhivananFailing to plan is Planning to fail
The dup thread is gone. So we will stick to this one KH[spoiler]Time is always against us[/spoiler] |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2008-08-27 : 03:30:54
|
| declare @orders table(sort_order int identity(1,1) empid int)insert into @orders(empid)select 3 as empidunion allselect 16 union all select 19 union allselect 2 union allselect 15union allselect 4 union allselect 7 union allselect 1 select e1.* from emp as e1 inner join @orders as e2 on e1.empid=e2.empidorder by e2.sort_orderMadhivananFailing to plan is Planning to fail |
 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2008-08-27 : 03:36:26
|
are you using SQL Server 2000 or 2005 ? KH[spoiler]Time is always against us[/spoiler] |
 |
|
|
|
|
|
|
|