Wednesday, October 17, 2012

SQL null CASE date trick

In Sql query if you want to check the date is null and select a date value you need to convert the date field to varchar.Otherwise the case statement will not run properly.
Eg.


CASE  WHEN a.RegDt='1900-01-01 00:00:00.000' THEN CAST(reg.LstUpd AS VARCHAR(32)) WHEN a.RegDt IS NULL  THEN CAST(REG.LstUpd AS VARCHAR(32)) ELSE a.RegDt END RegDt,

No comments:

Post a Comment