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)
 order by specific order?

Author  Topic 

jgonzalez14
Yak Posting Veteran

73 Posts

Posted - 2009-02-02 : 16:17:24
I want to use this select statement to find these id's in this order
15, 12, 34,44,2. How can you do this?


select *
from FDOH_Navigation
where id in (15,12,34,44,2)

sodeep
Master Smack Fu Yak Hacker

7174 Posts

Posted - 2009-02-02 : 16:56:31
[code]select * from FDOH_Navigation
Where id in (15,12,34,44,2)
Order by (Case When id = 15 then 0
When id = 12 then 1
When id = 34 then 2
When id = 44 then 3
When id = 2 then 4 Else id End)[/code]
Go to Top of Page

jgonzalez14
Yak Posting Veteran

73 Posts

Posted - 2009-02-02 : 17:01:54
Thank you works perfect
Go to Top of Page

sodeep
Master Smack Fu Yak Hacker

7174 Posts

Posted - 2009-02-02 : 17:02:28
Welcome .
Go to Top of Page
   

- Advertisement -