7

How to check for null in case statement in SQL Server 2008

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Rauf
  • 12,326
  • 20
  • 77
  • 126

3 Answers3

25
CASE WHEN column IS NULL THEN 1 ELSE 0 END
Mitch Wheat
  • 295,962
  • 43
  • 465
  • 541
5

Sometime you need case isnull(column, 99) when 99 then "null" when 1 then ....

pinichi
  • 2,199
  • 15
  • 17
-1

Using Case in Select Query:

Example:

SELECT UserID, UserName, CASE(UserAmendId) AS UID WHEN 0 THEN 'True' ELSE 'False' END 
FROM UserTable

It shows records with field UID=true where its Value=0, otherwise it show False where its Value is Null.

Table Name: UserTable
Columns: UserID (int), UserName (varchar(50)), UserAmendID (int)

Aziz Shaikh
  • 16,245
  • 11
  • 62
  • 79
Riya
  • 1