views:

81

answers:

1

Why does this..

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

Produce this

"An expression of non-boolean type specified in a context where a condition is expected, near 'Select'."

And is there a Boolean type in SQL2008?

+11  A: 

@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!'

Note that this also fails

if 1
    Select 'the sky is blue!'
ELSE
    Select 'the sky is not blue!'
Matthew Vines