EN VI

Sqlite - SQL select query - How to recognize NULL values in CASE?

2024-03-14 04:00:09
Sqlite - SQL select query - How to recognize NULL values in CASE

I have a SQL select query where I select columns from a table, some of which are in BLOB format. I want to display the BLOB column as either 'Yes' or 'No' based on if the column is null or not (if there is data or not).

I've tried using this case statement, however it always returns 'Yes', no matter if the value is null or not. How can I fix this?

select category,
description,
CASE maintenance
    when 1 then 'Yes'
    else 'No'
END maintenance,
submittedBy,
CASE image
    when NULL then 'No'
    else 'Yes'
END image
from Forms

Solution:

Values of NULL must be checked with IS so rewrite you query to

select category,
description,
CASE maintenance
    when 1 then 'Yes'
    else 'No'
END maintenance,
submittedBy,
CASE when image IS NULL then 'No'
    else 'Yes'
END image
from Forms
Answer

Login


Forgot Your Password?

Create Account


Lost your password? Please enter your email address. You will receive a link to create a new password.

Reset Password

Back to login