Skip to content
Advertisement

Using SELECT for simple BOOLEAN evaluation

I want to test some evaluations without working on any table. For example, you can write

SELECT 1+1
>2

I want to achieve something like this:

SELECT 2 > 1
>FALSE

I know that most engines don’t have the concept of a boolean data type, but I don’t know how their internal work (even if I guess everything <> 0 is true, like in C). Anyway, the format of the response really doesn’t matter, whether it’s true/false or 0/1

Advertisement

Answer

SELECT CASE WHEN 2 > 1 THEN 'True' ELSE 'False' END
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement