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:
Would be used to create the View:
This is the CASE:
ISNULLified by:
For the following Employees Table:
| EmployeeID | LastName | FirstName | Nickname |
|---|---|---|---|
| 39 | Carter | James | Jimmy |
| 40 | Reagan | Ronald | |
| 41 | Bush | George | |
| 42 | Clinton | William | Bill |
Would be used to create the View:
| EmployeeID | LastName | Handle |
|---|---|---|
| 39 | Carter | Jimmy |
| 40 | Reagan | Ronald |
| 41 | Bush | George |
| 42 | Clinton | Bill |
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
Comments