SQLTeam.com | Weblogs | Forums

Case syntax


#1

Hi,
I have three date fields : date1, date2 and date3 need to check to determine the checkDate value. I need to check if date1 is empty then use date2, and if date2 is empty then use date3.
The syntax below just gives me all null for checkDate. Please advise.

select
checkDate = case when date1 is null then date2
when date2 is null then date3
end

Thanks


#2

You could use
COALESCE(Date1, Date2, Date3)
or
CASE WHEN Date1 IS NULL THEN CASE WHEN Date2 IS NULL THEN DATE3 ELSE Date2 END ELSE Date1 END (I think.)


#3

Thanks