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
 General SQL Server Forums
 New to SQL Server Programming
 ORDER IN Particular sequence

Author  Topic 

jhon11
Starting Member

42 Posts

Posted - 2008-01-23 : 10:19:03
Hi,

I have a table in which there is 5 column ...one with numbers like...1,2,3,4,..20...and one column is with description....and other column with other details...

Now I want to disply my results in sequence followed by 1,2,3,4,5,17,18,15,16,10,11,20 with all other columns...so can anybody suggest me what to do..?

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2008-01-23 : 10:24:04
create a temp table with that sequence
id int, sequence int

join on the id and order on the sequence

_______________________________________________
Causing trouble since 1980
blog: http://weblogs.sqlteam.com/mladenp
SSMS Add-in that does a few things: www.ssmstoolspack.com <- new version out
Go to Top of Page

jhon11
Starting Member

42 Posts

Posted - 2008-01-23 : 10:48:00
hi,

how could i do the temp table..i couldnt get the logic...
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-01-23 : 11:21:14
[code]create table #temp
(
yourcol int,
SeqNo int
)
INSERT INTO #temp
SELECT 1,1
UNION ALL
SELECT 2,2
....

SELECT 17,6
UNION ALL
SELECT 18,7
UNION ALL
SELECT 15,8
...


Then take

SELECT t1.*
FROM YourTable t1
INNER JOIN #temp t2
ON t2.YourCol=t1.YourCol
ORDER BY t2.SeqNo[/code]
Go to Top of Page
   

- Advertisement -