This is a dumping ground of software development topics that I've run across and found interesting (mainly .NET development). Many topics are covered more thoroughly in other places, and much of the information is gleaned from other places, and I'll try to credit those sources when possible.

Friday, March 18, 2011

SQL: Sorting NULL Values

I was ordering a result set by a field that is nullable, but wanted any rows whose value for this field was null to be at the end of the set, not the beginning. Probably should have figured this out on my own, but you know how quick Mr. Google can provide the answer. This site had me up and running in a matter of seconds:

ORDER BY
   CASE
      WHEN Region IS NULL THEN 1
      ELSE 0
   END,
   Region

No comments:

Followers