有条件的SQL条件

mad*_*lor 4 sql t-sql sql-server sql-server-2005

为什么这个..

DECLARE @SkyBlue Bit
SET @SkyBlue = 1
IF @SkyBlue
    Select 'the sky is blue!'
ELSE
    Select 'the sky is not blue!'
Run Code Online (Sandbox Code Playgroud)

产生这个

"在预期条件的上下文中指定的非布尔类型的表达式,靠近'Select'."

SQL2008中是否有布尔类型?

Mat*_*nes 13

@SkyBlue有点,不是布尔值.尝试:

DECLARE @SkyBlue Bit
SET @SkyBlue = 1
IF @SkyBlue = 1
    Select 'the sky is blue!'
ELSE
    Select 'the sky is not blue!'
Run Code Online (Sandbox Code Playgroud)

请注意,这也失败了

if 1
    Select 'the sky is blue!'
ELSE
    Select 'the sky is not blue!'
Run Code Online (Sandbox Code Playgroud)