What is the best way to convert an int or null to boolean value in an SQL query?

To my knowledge (correct me if I’m wrong), there is no concept of literal boolean values in SQL. You can have expressions evaluating to boolean values, but you cannot output them.

This said, you can use CASE WHEN to produce a value you can use in a comparison:

SELECT 
    CASE WHEN ValueColumn IS NULL THEN 'FALSE' ELSE 'TRUE' END BooleanOutput 
FROM 
    table 

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)