By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,408 Members | 1,796 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,408 IT Pros & Developers. It's quick & easy.

order by specific values

P: n/a
Is it possible to order by specific values in a column. For example a
column may contain values like N, N1, N2, S, S1, S2, R, T. I want to
order by in such a way that all the records with N, N1, or N2 in that
specific column will show up on the top. All the records with S1, S2
values will show up next and finally all records with R and T values
in that specific column will show up. Please give me the select
syntax.
Sincerely,
Yasaswi Pulavarti
Jul 20 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
"Yasaswi Pulavarti" <ya*****@encfor.com> wrote in message
Is it possible to order by specific values in a column. For example a
column may contain values like N, N1, N2, S, S1, S2, R, T. I want to
order by in such a way that all the records with N, N1, or N2 in that
specific column will show up on the top. All the records with S1, S2
values will show up next and finally all records with R and T values
in that specific column will show up. Please give me the select
syntax.


select ...
from ...
order by case left(TABLE.COL, 1)

But in the above, N is first, then R, then S, then T. But the idea is
right. Just replace left(...) with an appropriate formula. You could even
use case end.

select ...
from ...
order by case left(TABLE.COL, 1) when 'N' then 1 when 'S' then 2 end
Jul 20 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.