How to output a boolean in T-SQL based on the content of a column? How to output a boolean in T-SQL based on the content of a column? sql sql

How to output a boolean in T-SQL based on the content of a column?


You have to use a CASE statement for this:

SELECT CASE WHEN columnName IS NULL THEN 'false' ELSE 'true' END FROM tableName;


Or you can do like this:

    SELECT RealColumn, CAST(0 AS bit) AS FakeBitColumn FROM tblTable


If you need a output as boolean

CAST(CASE WHEN colName IS NULL THEN 0  ELSE 1   END as BIT) aIsBooked