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.
| Author |
Topic |
|
sengoku
Starting Member
29 Posts |
Posted - 2003-07-31 : 08:03:09
|
| howdy doody...i'm sure this is well easy, but i just can't think of a good way to do it...i have a bunch of records with a 'position' - the position is either 0 (meaning unranked) or from 1 up to (record count) - which is a chart position.now, it's easy to select these in order :select * from records order by record_positionbut what i want to know is, can i order them so anything with record_position=0 comes AFTER everthing else? i could do it with 'order by record_position desc' but then everything else is back-to-front...any ideas? i'm sure one of you bright sparks will be able to see over my mental block here... :) |
|
|
Arnold Fribble
Yak-finder General
1961 Posts |
Posted - 2003-07-31 : 08:17:56
|
| ORDER BY CASE WHEN record_position = 0 THEN 1 ELSE 0 END, record_position |
 |
|
|
sengoku
Starting Member
29 Posts |
Posted - 2003-07-31 : 08:21:57
|
| beautiful. so simple, and so elegant.thanks a lot my friend! :) |
 |
|
|
|
|
|