5

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?

1 Answer 1

13

@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!'
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.