check for null date in CASE statement, where have I gone wrong?

Posted by James.Elsey on Stack Overflow See other posts from Stack Overflow or by James.Elsey
Published on 2010-03-16T11:43:16Z Indexed on 2010/03/16 11:46 UTC
Read the original article Hit count: 134

Hello,

My source table looks like this

Id     StartDate
1      (null)
2      12/12/2009
3      10/10/2009

I want to create a select statement, that selects the above, but also has an additional column to display a varchar if the date is not null such as :

Id     StartDate    StartDateStatus
1      (null)       Awaiting
2      12/12/2009   Approved
3      10/10/2009   Approved

I have the following in my select, but it doesn't seem to be working. All of the statuses are set to Approved even though the dates have some nulls

        select
             id,
             StartDate,
        CASE StartDate
        WHEN null THEN 'Awaiting'
        ELSE 'Approved' END AS StartDateStatus
        FROM myTable

The results of my query look like :

Id     StartDate    StartDateStatus
1      (null)       Approved
2      12/12/2009   Approved
3      10/10/2009   Approved
4      (null)       Approved
5      (null)       Approved

StartDate is a smalldatetime, is there some exception to how this should be treated?

Thanks

© Stack Overflow or respective owner

Related posts about sql

Related posts about case