Skip to main content

Posts

Showing posts from June, 2009

The Case IsNull Now

In SQL Server views I've been using CASE statements to look for nulls for years. I've just nullified this practice.

For the following Employees Table:
EmployeeIDLastNameFirstNameNickname39CarterJamesJimmy40ReaganRonald41BushGeorge42ClintonWilliamBill

Would be used to create the View:
EmployeeIDLastNameHandle39CarterJimmy40ReaganRonald41BushGeorge42ClintonBill

This is the CASE:SELECT EmployeeID , LastName , CASE Nickname WHEN Null THEN FirstName ELSE Nickname END As Handle FROM Employees
ISNULLified by:SELECT EmployeeID , LastName , ISNULL(Nickname, FirstName) AS Handle FROM Employees