Skip to content
Advertisement

How can I declare a Boolean parameter in SQL statement?

How can I declare a Boolean parameter in SQL statement?

Advertisement

Answer

The same way you declare any other variable, just use the bit type:

DECLARE @MyVar bit
Set @MyVar = 1  /* True */
Set @MyVar = 0  /* False */

SELECT * FROM [MyTable] WHERE MyBitColumn = @MyVar

Note this is semantically different from a true boolean. The 1/0 values won’t always just map to true/false the way you might expect.

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement