I want to print a simple statement
print (1=1), i expect the result to be TRUE or 1 but sql server tell me:
Incorrect syntax near ‘=’.
why is that?
Same will happen for a statement like that
declare @test bit
set @test = (1=1)
in summary how can i “see” what is returned from a comparison without using an IF statement
Update: The reason i’m asking is because i’m trying to debug why the following statement
declare @AgingAmount smallint
set @AgingAmount = 500
select Amount, datediff(day,Batch.SubmitDate,getdate()) as Aging from myreporrt
where datediff(day,Batch.SubmitDate,getdate()) > @AgingAmount
will return all rows even with aging of 300
so i wanted to test if datediff(day,datesubmited,getdate()) > 500 returns true or false but could not find a way how to display the result of this comparison.
Although SQL Server has the concept of a
booleantype, and it understands expressions that resolve to abooleaninIFandWHEREclauses, it does not support declaringbooleanvariables or parameters. Thebitdata type cannot store the result of abooleanexpression directly, even though it looks suspiciously like one.The nearest you can get to a
booleandata type is this:To add to the confusion, SQL Server Management Studio treats
bitlikebooleanwhen displaying results, and ADO.NET mapsbittoSystem.Booleanwhen passing data back and forth.Update: To answer your latest question, use the
case when ... then 1 else 0 endsyntax in theselectstatement.