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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

sort query according to the IN parameters

Status
Not open for further replies.

taixut

Programmer
Oct 27, 2003
39
ES
Hi all,

i would like to build a query that it sorts the results according to the parameters I pass to the IN clause.

Example:

I have a table with this info:

NUM TYPE TEXT
--------------------
1 app night
2 app evening
3 app morning
4 exec sunday
.....

select * from table where text in ('sunday','evening','morning')

i want the query returns the results in the order sunday, evening, morning... like:

4 exec sunday
2 app evening
3 app morning


is there a way to sort the results like that?

Thanx in advance





 
You can use Order By with Case.
Something like this

select * from table
where text in ('sunday','evening','morning')
ORDER BY CASE WHEN text = 'sunday' THEN 1
WHEN text = 'evening' THEN 2
WHEN text = 'morning' THEN 3
END
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top