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)
 ordering by an arbitrary list...?

Author  Topic 

sengoku
Starting Member

29 Posts

Posted - 2004-06-11 : 14:22:19
hey there people :)

i was just thinking. is it possible to have a list of data in sql (could be number or text)ordered by a list you've already built?

err. that doesn't make sense does it? :D

i mean, can you do something like this :

select myname,count(myhits) as myhitcounter from table where myname in ('chris','dave','bob') order by
case when myname='chris' then 0 else
case when myname='dave' then 1 else
case when myname='bob' then 2 else
3
end
end
end

without that horrible case structure on the end? :D

...and while you're here, just how slow is running multiple case when's on a column as i do above?

thanks for any advice, and i hope you all have a nice weekend :)

ehorn
Master Smack Fu Yak Hacker

1632 Posts

Posted - 2004-06-11 : 15:20:29
One option is to store your pre-built list in a table with an ordered column and then join it back to your results ordered by the pre-built list.
Go to Top of Page
   

- Advertisement -