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 2000 Forums
 SQL Server Development (2000)
 order by using a custom value

Author  Topic 

sandeepkashaboina
Starting Member

1 Post

Posted - 2011-09-16 : 11:17:01
After executing the query I got the following data:

select pkid, firstname from customer order by firstname

pkid firstname
4 Name1
5 Name2
3 Name3
1 Sandeep
6 Name3

But I need the result as following:

pkid firstname
1 Sandeep
4 Name1
5 Name2
3 Name3
6 Name3


'Sandeep' should always come first:
something like: select pkid, firstname from customer order by 'sandeep', firstname

Help needed !!
Thanks.

ehorn
Master Smack Fu Yak Hacker

1632 Posts

Posted - 2011-09-16 : 11:21:10
Hello,

Perhaps you could use a CASE statement in the ORDER BY clause. Something like;

ORDER BY CASE WHEN firstname = 'SanDeep' THEN 'A' ELSE firstname END ASC, pkid ASC


HTH.
Go to Top of Page

russell
Pyro-ma-ni-yak

5072 Posts

Posted - 2011-09-16 : 11:23:26
order by case when firstname = 'Sandeep' then 0 else 1 end, firstname

Go to Top of Page
   

- Advertisement -