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)
 SQL Order By

Author  Topic 

amarflora
Starting Member

4 Posts

Posted - 2008-12-19 : 10:44:05
Is there any way to order by a particular alphabet. For example I have the following table with the entries

FA1233
AA2321
YH1232

I want to order by "FA" first and then by AA

Thanks for your help!

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2008-12-19 : 10:48:00
and where does the yh come in? by what alphabet?

___________________________________________________________________________
Causing trouble since 1980
Blog: http://weblogs.sqlteam.com/mladenp
Speed up SSMS development: www.ssmstoolspack.com <- version 1.1 out!
Go to Top of Page

amarflora
Starting Member

4 Posts

Posted - 2008-12-19 : 10:52:01
Well its just a table format. I dont mind Sorting it by 'FA' first and then regular sorting because I want to show the 'FA' values on top. Thanks.
Go to Top of Page

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2008-12-19 : 10:59:25
select ...
from table...
where ...
order by case when yourColumn like 'FA%' then 0 else 1 end

___________________________________________________________________________
Causing trouble since 1980
Blog: http://weblogs.sqlteam.com/mladenp
Speed up SSMS development: www.ssmstoolspack.com <- version 1.1 out!
Go to Top of Page

Jai Krishna
Constraint Violating Yak Guru

333 Posts

Posted - 2008-12-19 : 22:55:42
select col from table
order by case when yourColumn like 'FA%' then '0' else col end



Jai Krishna
Go to Top of Page
   

- Advertisement -