|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
SlickEdit: Code in over 40 languages across 7 platforms. SlickEdit’s unmatched power, speed, and flexibility allows even the most accomplished developers to write better code faster. Download a free trial today! |
|
#1
|
|||
|
|||
|
sorting with NULLs at bottom
I have a result set that I'm sorting by a nullable field. By default it puts the nulled rows at the top. I want them at the bottom without changing the order of the non-nulled rows.
One way that I've thought to do this is some kind of combination of these queries: SELECT * from myTable WHERE NOT (myField IS NULL ) ORDER BY myField and SELECT * FROM myTable WHERE myField IS NULL I suppose there's some kind of join construct for this, but I don't know it. Any help would be appreciated. |
|
#2
|
||||
|
||||
|
Code:
select *
from myTable
order
by case when myField is null then 1 else 0 end
, myField
http://r937.com/ |
![]() |
| Viewing: Dev Shed Forums > Databases > MS SQL Development > sorting with NULLs at bottom |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|