Tuesday, June 5, 2012

give boolean value based on IS NULL and not ISNULL

If emp.InactiveDate is a possibly null DateTime and you wish to set a column in a view to true if it is null, this is not the way to go:

ISNULL(emp.InactiveDate, '2000-01-01') as Active

 
 

A better way to go:

(CASE WHEN emp.InactiveDate IS NULL THEN 'True' ELSE 'False' END) as Active

No comments:

Post a Comment