04pallav
9/13/2017 - 9:52 PM

COALESCE

COALESCE

COALESCE can be useful when you want to replace a NULL value with some other value.

COALESCE(x,y,z) = x if x is not NULL
COALESCE(x,y,z) = y if x is NULL and y is not NULL
COALESCE(x,y,z) = z if x and y are NULL but z is not NULL
COALESCE(x,y,z) = NULL if x and y and z are all NULL


SELECT name, party
      ,COALESCE(party,'None') AS aff
  FROM msp WHERE name LIKE 'C%'      ###NULL values are replaced by None
  
  
ISNULL(col,777)  
#### reverse of coalesce