Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SELECT 1=1 not working

Tags:

sql-server

My question is a bit more generic, but let's say I want to test some expression in SQL Server. I write SELECT 1=1 or SELECT 'a' > 'B' and press F5, hoping to see the result, like I do when I type SELECT 0, 1.
But I get an error instead. Why is that? What should I use to evaluate those expressions on the fly?

like image 535
iDevlop Avatar asked Jan 13 '11 15:01

iDevlop


2 Answers

SQL Server doesn't have a boolean data type.

You would need to use SELECT CASE WHEN 1=1 THEN 1 ELSE 0 END

like image 67
Martin Smith Avatar answered Sep 27 '22 21:09

Martin Smith


Simplest way is to select 1 where <test expression here>

like image 36
dotjoe Avatar answered Sep 27 '22 21:09

dotjoe