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
 General SQL Server Forums
 New to SQL Server Programming
 SELECT WHERE IN ('value1, 'value2') sort
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

forefj
Starting Member

10 Posts

Posted - 05/14/2012 :  14:30:25  Show Profile  Reply with Quote
I have a Query with a long list of values (hundreds). I need to have the values returned in the order they are entered into the query,if possible.
For example:
SELECT column
FROM
Table
Where In (Value1,Value2,Value3,Value4,Value5)
I would like for the return values to be displayed in the order they are listed in the query. The standard Order By Column will not work because
the values are returned in alphabetical order, in this case I need them to be returned as listed in the query. Can this be done? If so can you show me how. Thanks.

tkizer
Almighty SQL Goddess

USA
35017 Posts

Posted - 05/14/2012 :  14:32:32  Show Profile  Visit tkizer's Homepage  Reply with Quote
ORDER BY CASE WHEN Col10 = 'Value1' THEN 1, WHEN Col10 = 'Value2' THEN 2, ...

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

madhivanan
Premature Yak Congratulator

India
22469 Posts

Posted - 05/16/2012 :  05:34:03  Show Profile  Send madhivanan a Yahoo! Message  Reply with Quote
or store values in a temp table that has identity column. Use join and order by identity column

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
48056 Posts

Posted - 05/16/2012 :  20:55:19  Show Profile  Reply with Quote
i would prefer temp table solutions especially if number of values involved are large

------------------------------------------------------------------------------------------------------
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.09 seconds. Powered By: Snitz Forums 2000