SQL Server - boolean literal?

前端 未结 13 885
深忆病人
深忆病人 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条回答
  •  庸人自扰
    2020-12-04 23:57

    SQL Server does not have literal true or false values. You'll need to use the 1=1 method (or similar) in the rare cases this is needed.

    One option is to create your own named variables for true and false

    DECLARE @TRUE bit
    DECLARE @FALSE bit
    SET @TRUE = 1
    SET @FALSE = 0
    
    select * from SomeTable where @TRUE = @TRUE
    

    But these will only exist within the scope of the batch (you'll have to redeclare them in every batch in which you want to use them)

提交回复
热议问题