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 2005 Forums
 Transact-SQL (2005)
 Order by String/Integer format

Author  Topic 

djorre
Yak Posting Veteran

94 Posts

Posted - 2009-08-13 : 04:48:14
Hi friends,
I got a question about ordening:

Select Id from tblUnits
Result =>
Id (string)
9
10
11
9,10,11

I need

Select Id from tblUnits
Order by ...
Result =>
Id (string)
9,10,11
9
10
11

How to do this? I have been thinking but not found anything yet. Can you help?

Thanks in advance, Joris

Nageswar9
Aged Yak Warrior

600 Posts

Posted - 2009-08-13 : 04:52:11
select * from @temp
order by case when id = '9,10,11' then 0 else 1 end
Go to Top of Page

Nageswar9
Aged Yak Warrior

600 Posts

Posted - 2009-08-13 : 04:54:37
( or )
select * from @temp
order by case when id like ('9,10,11') then 0 else 1 end
Go to Top of Page

bklr
Master Smack Fu Yak Hacker

1693 Posts

Posted - 2009-08-13 : 04:57:02
select * from tablename
order by case when charindex(',',id) > 0 then 0 else 1 end
Go to Top of Page
   

- Advertisement -