Boolean expression as column value in sql transaction

In most DBMS: es this work:

select (5 > 3) 

and evaluates to true. It does not work in MS Transact SQL, and the only workaround I found is to write:

 select case when 5 > 3 then 1 else 0 end 

Which view sucks because it is much more detailed. Is there a better way to write the checks described above?

+6
sql sql-server tsql
source share
3 answers

If the problem is arithmetic comparison:

 select (5 - 3) 

Then, when testing the application level for <or = or> 0.

+2
source share

If your program often needs such case constructors, you can create your own set of functions that will have user-defined functions, such as Bool_IsGreater(left, right) , which will return you your zero 0 or 1.

SQL Server does not support boolean type in any case, even for using a base column.

If you need performance, and these values โ€‹โ€‹5 and 3 will naturally come from some select query, you can create a new column and set its value to 1 or 0 using a trigger or something else that can help in performance.

0
source share

You can write it as a scalar function, but it will be very slow in large data sets.

0
source share

All Articles