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 a value in a field?

Author  Topic 

biggs
Starting Member

10 Posts

Posted - 2006-02-08 : 21:43:10
Is it possible to order by a value in a field? For example, let's say you want to return all books sorted by LastName, but you want books written by 'Orwell' to show up first in your output.

Just curious.

Tony

Michael Valentine Jones
Yak DBA Kernel (pronounced Colonel)

7020 Posts

Posted - 2006-02-08 : 22:56:06
[code]select
*
from
MyTable
order by
case LastName when 'Orwell' then 0 else 1 end,
LastName
[/code]

CODO ERGO SUM
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2006-02-09 : 01:48:14
or

select
*
from
MyTable
order by
case when LastName ='Orwell' then 1 else 2 end


Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -