In the following snippet, I am getting an error in line #4 (Incorrect Syntax near ‘=’). I need to have an equality result displayed as a column in a select statement.
declare @five int
set @five = 5
declare @bool bit
set @bool = (@five = 6)
select @five, @bool
The result set should have two columns:
5 false
T-SQL does not have a real boolean type. It is a weird situation. Here is the solution:
Truth expressions, which would be of boolean type in other languages, don’t have a type in T-SQL. You can only use truth expressions in special syntactic places like
where,ifandcase.