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)
 Query

Author  Topic 

sunitagoswami
Starting Member

10 Posts

Posted - 2006-11-07 : 10:41:11
I have a table containing
CITYDESC
Bangalore
BangaloreNEW
Baroda
Mumbai
Chennai
Bangalore WEST
EAST Bangalore
BangaloreONE
OLD Bangalore

I want a query which will fetch me the result as

CITYDESC
Bangalore
Bangalore WEST
BangaloreNEW
BangaloreONE
EAST Bangalore
OLD Bangalore
Baroda
Chennai
Mumbai

Please help


Sunita

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2006-11-07 : 10:44:21
what kind of order is that?



Go with the flow & have fun! Else fight the flow
blog thingie: http://weblogs.sqlteam.com/mladenp
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2006-11-07 : 10:46:29
Is this what you want ?


declare @table table
(
CITYDESC varchar(20)
)
insert into @table
select 'Bangalore' union all
select 'BangaloreNEW' union all
select 'Baroda' union all
select 'Mumbai' union all
select 'Chennai' union all
select 'Bangalore WEST' union all
select 'EAST Bangalore' union all
select 'BangaloreONE' union all
select 'OLD Bangalore'

select CITYDESC
from @table
order by case when CITYDESC like '%Bangalore%' then 0 else 1 end, CITYDESC




KH

Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2006-11-07 : 10:47:15
" what kind of order is that? "
The order of Bangalore !


KH

Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2006-11-07 : 10:55:17
West, New, One, East and Old are not part primary sort keys.


Peter Larsson
Helsingborg, Sweden
Go to Top of Page

sunitagoswami
Starting Member

10 Posts

Posted - 2006-11-08 : 01:29:44
Dear khtan,
Thanks a ton!!
I was not knowing that we can use CASE statement in Order by


Sunita
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2006-11-08 : 02:00:40
What if table contains city name "Aurangabad"?


Peter Larsson
Helsingborg, Sweden
Go to Top of Page

harsh_athalye
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2006-11-08 : 02:38:25
quote:
What if table contains city name "Aurangabad"?


Wow!

You know a lot about Indian cities!!

Harsh Athalye
India.
"Nothing is Impossible"
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2006-11-08 : 03:06:00
I know Google is my friend


Peter Larsson
Helsingborg, Sweden
Go to Top of Page
   

- Advertisement -