SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 How to select data in below order?
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

itnagaraj
Yak Posting Veteran

India
68 Posts

Posted - 01/29/2013 :  02:26:48  Show Profile  Reply with Quote
The data should stroed in below order.
FormatId FormatDescription
1 Full Proposal w/Purchase Agreement
2 Short Proposal/Purchase Agreement
3 Purchase Agreement
4 Other
5 Test data
6 NA

But i would need to select the data in below format.

Alphabetical order First and "other" and "NA" should be at the end of the list.

V.NAGARAJAN

visakh16
Very Important crosS Applying yaK Herder

India
52309 Posts

Posted - 01/29/2013 :  02:48:29  Show Profile  Reply with Quote

SELECT *
FROM Table
ORDER BY CASE FormatDescription
         WHEN 'Other' THEN 1
         WHEN 'N/A' THEN 2
         ELSE 0
         END ASC,FormatDescription ASC


------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Edited by - visakh16 on 01/29/2013 02:49:01
Go to Top of Page

itnagaraj
Yak Posting Veteran

India
68 Posts

Posted - 01/29/2013 :  03:01:10  Show Profile  Reply with Quote
It will work. Thanks for your help.
quote:
Originally posted by visakh16


SELECT *
FROM Table
ORDER BY CASE FormatDescription
         WHEN 'Other' THEN 1
         WHEN 'N/A' THEN 2
         ELSE 0
         END ASC,FormatDescription ASC


------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/




V.NAGARAJAN
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
52309 Posts

Posted - 01/29/2013 :  03:06:08  Show Profile  Reply with Quote
welcome

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.16 seconds. Powered By: Snitz Forums 2000