SQL conditional bit

Why does this.

DECLARE @SkyBlue Bit
SET @SkyBlue = 1
IF @SkyBlue
    Select 'the sky is blue!'
ELSE
    Select 'the sky is not blue!'

Produce it

"An expression of a non-boolean type specified in the context where the condition is expected to be about."

And is there a Boolean type in SQL2008?

+3
source share
1 answer

@SkyBlue is a bit, not a boolean. Try:

DECLARE @SkyBlue Bit
SET @SkyBlue = 1
IF @SkyBlue = 1
    Select 'the sky is blue!'
ELSE
    Select 'the sky is not blue!'

Please note that this also does not work.

if 1
    Select 'the sky is blue!'
ELSE
    Select 'the sky is not blue!'
+13
source

Source: https://habr.com/ru/post/1717263/


All Articles