select – Return Bit Value as 1/0 and NOT True/False in SQL Server

select – Return Bit Value as 1/0 and NOT True/False in SQL Server

Try with this script, maybe will be useful:

SELECT CAST(TRUE as bit) -- RETURN 1
SELECT CAST(FALSE as bit) --RETURN 0

Anyway I always would use a value of 1 or 0 (not TRUE or FALSE). Following your example, the update script would be:

Update Table Set BitField=CAST(TRUE as bit) Where ID=1

Modify your query to generate the output that you want.

Try casting them to int:

select cast(bitFlag as int)

Or, if you like, use case:

select (case when bitFlag = 0 then 0 else 1 end)

select – Return Bit Value as 1/0 and NOT True/False in SQL Server

This can be changed to 0/1 through using CASE WHEN like this example:

SELECT 
 CASE WHEN SchemaName.TableName.BitFieldName = true THEN 1 ELSE 0 END AS bit Value 
 FROM SchemaName.TableName

Leave a Reply

Your email address will not be published.