all groups > sql server programming > december 2005 >
You're in the

sql server programming

group:

Problem with order by clause


Problem with order by clause shiva
12/4/2005 9:51:00 PM
sql server programming:
Hi! Guys

i have problem with order by clause.

i have table some T1 with two columns say Itemname and Status

and data like this

ItemName Status
T1 G
T2 D
T3 US
T4 S
T5 G

Now i want to show with status like
G
D
S
US

plz , give solution
Re: Problem with order by clause shiva
12/4/2005 10:42:07 PM

thanks Steve , its working fine.

[quoted text, click to view]
Re: Problem with order by clause Steve Kass
12/5/2005 1:07:21 AM
Either of these ORDER BY clauses should work:

ORDER BY
CASE Status
WHEN 'G' THEN 0
WHEN 'D' THEN 1
WHEN 'S' THEN 2
WHEN 'US' THEN 3 END

or

ORDER BY
CHARINDEX('/'+Status+'/','/G/D/S/US/')

Steve Kass
Drew University

[quoted text, click to view]
AddThis Social Bookmark Button