How to write literal boolean value in SQL Server? See sample use:
select * from SomeTable where PSEUDO_TRUE
another sample:
if PSEUDO_TRUE begin select 'Hello, SQL!' end
Note: The query above has nothing to do with how I'm going to use it. It is just to test the literal boolean.
There is no boolean data type in SQL Server. However, a common option is to use the BIT data type. A BIT data type is used to store bit values from 1 to 64. So, a BIT field can be used for booleans, providing 1 for TRUE and 0 for FALSE.
A Boolean literal is a character-string delimited on the left by the separator B" and on the right by the quotation mark separator. The character-string consists only of the character 0 or 1. The value of a Boolean literal is the character itself, excluding the delimiting separators.
SQL - Boolean Data A Boolean table column will contain either string values of "True" and "False" or the numeric equivalent representation, with 0 being false and 1 being true.
In SQL Server, a literal is the same as a constant. We'll cover several types of literals - string, integer, decimal, and datetime literals.
SQL Server doesn't have a boolean data type. As @Mikael has indicated, the closest approximation is the bit. But that is a numeric type, not a boolean type. In addition, it only supports 2 values - 0
or 1
(and one non-value, NULL
).
SQL (standard SQL, as well as T-SQL dialect) describes a Three valued logic. The boolean type for SQL should support 3 values - TRUE
, FALSE
and UNKNOWN
(and also, the non-value NULL
). So bit
isn't actually a good match here.
Given that SQL Server has no support for the data type, we should not expect to be able to write literals of that "type".
select * from SomeTable where 1=1
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With