SQL Server - boolean literal?

前端 未结 13 861
深忆病人
深忆病人 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

    I question the value of using a Boolean in TSQL. Every time I've started wishing for Booleans & For loops I realised I was approaching the problem like a C programmer & not a SQL programmer. The problem became trivial when I switched gears.

    In SQL you are manipulating SETs of data. "WHERE BOOLEAN" is ineffective, as does not change the set you are working with. You need to compare each row with something for the filter clause to be effective. The Table/Resultset is an iEnumerable, the SELECT statement is a FOREACH loop.

    Yes, "WHERE IsAdmin = True" is nicer to read than "WHERE IsAdmin = 1"

    Yes, "WHERE True" would be nicer than "WHERE 1=1, ..." when dynamically generating TSQL.

    and maybe, passing a Boolean to a stored proc may make an if statement more readable.

    But mostly, the more IF's, WHILE's & Temp Tables you have in your TSQL, the more likely you should refactor it.

    0 讨论(0)
提交回复
热议问题