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.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 How to get Resultset in the order of Items given i

Author  Topic 

vidvijay
Starting Member

4 Posts

Posted - 2007-11-01 : 06:47:16
hi,



My query is

select * from Items where ItemId in
(4354,14759 ,62990,105170,105244,14741,58495,14742,49798,14743,58496,14744,71631)

I'm getting the resultant set in the random order.. like this


4354
14741
14742
14743
14744
14759
49798
58495
58496
62990
71631
105170
105244


How to retrive as same as i have given inside IN clause

i.e --> In this order 4354,14759 ,62990,105170,105244,14741,58495,14742,49798,14743,58496,14744,71631

Any help would be very uself.

Thanks in Advance

Vidhya

Kristen
Test

22859 Posts

Posted - 2007-11-01 : 06:56:40
ORDER BY CASE ItemId WHEN 4354 THEN 1 WHEN 14759 THEN 2 WHEN ... WHEN 71631 THEN 12 ELSE 9999 END

Or pass the IN list as a parameter and JOIN to the results of a SPLIT function; SPLIT functions usually have an "Item Number", you can then sort on that.

Kristen
Go to Top of Page

vidvijay
Starting Member

4 Posts

Posted - 2007-11-01 : 07:38:14

Hi Kristen,

Thanks a ton..

It helped me a lot..
Go to Top of Page
   

- Advertisement -