How to set bool value in SQL
You need case statement with when and else if not any condition satisfied
Update [mydb].[dbo].[myTable]
SET isTrue = ( CASE WHEN Name = 'Jason'
THEN 1 else 0
END)
Sql server does not expose a boolean
data type which can be used in queries.
Instead, it has a bit
data type where the possible values are 0
or 1
.
So to answer your question, you should use 1
to indicate a true
value, 0
to indicate a false
value, or null
to indicate an unknown value.
Update [mydb].[dbo].[myTable]
SET isTrue =
CASE WHEN Name = 'Jason' THEN
1
ELSE
0
END
The query you added will work fine, but it will you have to take care of "FALSE" part as well otherwise it will try to enter NULL in your column. Do you have any default value constrain on isTrue column?
Update [mydb].[dbo].[myTable]
SET isTrue =
(
CASE WHEN Name = 'Jason' THEN 1 ELSE 0
END
)