Search code examples
sqlcasesqlanywhere

CASE expression for NULL condition is not working


I have an SQL query where the case expression is not working because I am getting the NULL value.

Any idea how to fix this?

select 
td.reportEndDate,
    CASE td.originalLinearAirDate
    WHEN NULL THEN '12345678'
    END As originalLinearAirDate
from 
FROM DBA.Telecast td 
where id = 2
order by
td.reportEndDate,
originalLinearAirDate;

Solution

  • You can use isnull

    select 
    td.reportEndDate,
        CASE WHEN td.originalLinearAirDate IS NULL THEN '19000101'
             ELSE td.originalLinearAirDate 
        END As originalLinearAirDate
    from 
    FROM DBA.Telecast td 
    where id = 2
    order by
    td.reportEndDate,
    originalLinearAirDate;