| Author |
Topic |
|
sunitagoswami
Starting Member
10 Posts |
Posted - 2006-11-07 : 10:41:11
|
I have a table containingCITYDESCBangaloreBangaloreNEWBarodaMumbaiChennaiBangalore WESTEAST BangaloreBangaloreONEOLD BangaloreI want a query which will fetch me the result asCITYDESCBangaloreBangalore WESTBangaloreNEWBangaloreONEEAST BangaloreOLD BangaloreBarodaChennaiMumbaiPlease 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 |
 |
|
|
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 @tableselect 'Bangalore' union allselect 'BangaloreNEW' union allselect 'Baroda' union allselect 'Mumbai' union allselect 'Chennai' union allselect 'Bangalore WEST' union allselect 'EAST Bangalore' union allselect 'BangaloreONE' union allselect 'OLD Bangalore'select CITYDESCfrom @tableorder by case when CITYDESC like '%Bangalore%' then 0 else 1 end, CITYDESC KH |
 |
|
|
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 |
 |
|
|
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 LarssonHelsingborg, Sweden |
 |
|
|
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 bySunita |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2006-11-08 : 02:00:40
|
| What if table contains city name "Aurangabad"?Peter LarssonHelsingborg, Sweden |
 |
|
|
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 AthalyeIndia."Nothing is Impossible" |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2006-11-08 : 03:06:00
|
I know Google is my friend Peter LarssonHelsingborg, Sweden |
 |
|
|
|