SQL Server - boolean literal?

前端 未结 13 913
深忆病人
深忆病人 2020-12-04 22:56

How to write literal boolean value in SQL Server? See sample use:

select * from SomeTable where PSEUDO_TRUE

another sample:



        
13条回答
  •  旧时难觅i
    2020-12-04 23:31

    This isn't mentioned in any of the other answers. If you want a value that orms (should) hydrate as boolean you can use

    CONVERT(bit, 0) -- false CONVERT(bit, 1) -- true

    This gives you a bit which is not a boolean. You cannot use that value in an if statement for example:

    IF CONVERT(bit, 0)
    BEGIN
        print 'Yay'
    END
    

    woudl not parse. You would still need to write

    IF CONVERT(bit, 0) = 0
    

    So its not terribly useful.

提交回复
热议问题