What I Learned About SQL on August 7, 2004

(File under: Posts that were meant to be but never were)

  1. COALESCE() – the ANSI standard
  2. ISNULL() – the Microsoft T-SQL standard (only takes two values)
  3. IFNULL() – the MySQL standard (only takes two values)
  4. NVL() – Oracle / Informix PL/SQL standard (only takes two values)

Got that from a message board.

Basically it takes a query result, and in order of the parameters, if the first is NULL, then it uses the second parameter (often a string or ‘N/A’ or whatever.

SQL Server: Coalesce()

SQL Server: Isnull()

Kind of useful when you want to munge strings — because anything + NULL is always null, you can avoid that by doing

COALESCE(TABLE.WHATEVER,”)+ ‘anything’

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.