How to check for NULL in a CASE statement with a Scalar Function?

sql-server, t-sql

Solution

You are using the wrong style of `CASE` - you need to use `CASE WHEN <expression> THEN` not `CASE <expression> WHEN <expression> then`:

SELECT CASE 
 WHEN dbo.fnCarerResponse('') IS NULL
 THEN 'Pass'
 ELSE 'Fail'
END

Problem

How do you check for `NULL` in a `CASE` statement, when you're using a `Scalar Function`? My original query was ... but it fails ``` SELECT CASE dbo.fnCarerResponse('') WHEN NULL THEN 'Pass' ELSE 'Fail' END ``` I read the SO question about using `IS NULL`, like so ... ``` SELECT CASE dbo.fnCarerResponse('') IS NULL WHEN NULL THEN 'Pass' ELSE 'Fail' END ``` but this gives the `incorrect syntax near the keyword is` error Can you have a `Scalar Function` in the `CASE` ?

Original source

Related problems