Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

order by IN 1

Status
Not open for further replies.

vincer

Programmer
Mar 12, 2002
45
0
0
GB
if i have a statement such as

select * from customers where custid in (5,10,7,3)

is there any way to get the result set ordered in the same order as the IN list is specified?

Thanks
Vince
 
Code:
SELECT *
FROM customers
WHERE custid IN (5, 10, 7, 3)
ORDER BY CASE custid
  WHEN 5 THEN 1
  WHEN 10 THEN 2
  WHEN 7 THEN 3
  WHEN 3 THEN 4
  END

I know your query was only an example but hopefully you get the idea. --James
 
Thanks,
I can build this case statement up with my app as the list will only have upto 10 elements
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top