SQL Server - 布尔文字?
如何在 SQL Server 中写入文字布尔值?查看示例使用:
How to write literal boolean value in SQL Server? See sample use:
select * from SomeTable where PSEUDO_TRUE
另一个示例:
if PSEUDO_TRUE
begin
select 'Hello, SQL!'
end
注意:上面的查询与我将如何使用它无关.这只是为了测试文字布尔值.
Note: The query above has nothing to do with how I'm going to use it. It is just to test the literal boolean.
推荐答案
SQL Server 没有布尔值 数据类型.正如@Mikael 所指出的,最接近的近似值是位.但那是数字类型,而不是布尔类型.此外,它只支持 2 个值 - 0
或 1
(以及一个非值,NULL
).
SQL Server doesn't have a boolean data type. As @Mikael has indicated, the closest approximation is the bit. But that is a numeric type, not a boolean type. In addition, it only supports 2 values - 0
or 1
(and one non-value, NULL
).
SQL(标准 SQL,以及 T-SQL 方言)描述了一个三值逻辑.SQL 的布尔类型应支持 3 个值 - TRUE
、FALSE
和 UNKNOWN
(以及非值 NULL代码>).所以
bit
在这里实际上并不是一个很好的匹配.
SQL (standard SQL, as well as T-SQL dialect) describes a Three valued logic. The boolean type for SQL should support 3 values - TRUE
, FALSE
and UNKNOWN
(and also, the non-value NULL
). So bit
isn't actually a good match here.
鉴于 SQL Server 不支持 数据类型,我们不应期望能够编写该类型"的文字.
Given that SQL Server has no support for the data type, we should not expect to be able to write literals of that "type".
相关文章