How to output a boolean in T-SQL based on the content of a column?
If you need a output as boolean
CAST(CASE WHEN colName IS NULL THEN 0 ELSE 1 END as BIT) aIsBooked
for the column in the view you can use something like
CASE WHEN ColumnName is not null THEN 'True' ELSE 'False' END
or in a statement
SELECT
s.ID,
s.[Name],
CASE WHEN s.AchievedDate is not null THEN 'True' ELSE 'False' END [IsAchieved]
FROM Schools s
or for further processing afterwards I would personally use
SELECT
s.ID,
s.[Name],
CASE WHEN s.AchievedDate is not null THEN 1 ELSE 0 END [IsAchieved]
FROM Schools s
Or you can do like this:
SELECT RealColumn, CAST(0 AS bit) AS FakeBitColumn FROM tblTable
You have to use a CASE statement for this:
SELECT CASE WHEN columnName IS NULL THEN 'false' ELSE 'true' END FROM tableName;