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 2000 Forums
 SQL Server Development (2000)
 SQL Ordering

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2002-01-29 : 17:29:16
Ugur Ozyilmazel writes "Dir Sir/Madam,
Lets say :

"SELECT * FROM X WHERE ID IN (8,5,6)"

This string get only 8,5,6 ...
but sorts it ASC or DESC

all i need is to have them like what wrote...
order has to be lik 8,5,6...

do you know how?

Thank you"

andre
Constraint Violating Yak Guru

259 Posts

Posted - 2002-01-29 : 17:48:51
You could parse the comma-delimited string into a temp table with an identity field and sort by the identity field. The temp table would look like this:


CREATE TABLE #Temp (
Rownum int identity,
ID int
)


This article will tell you how to populate the temporary table using the comma-delimited string:
[url]http://www.sqlteam.com/item.asp?ItemID=2652[/url]

Your final SQL statement would look like this:

SELECT * FROM X INNER JOIN #Temp ON X.ID=#Temp.ID ORDER BY #Temp.Rownum;


Go to Top of Page
   

- Advertisement -