gpt4 book ai didi

sql - 从 SQL 中的位字段获取 -1

转载 作者:行者123 更新时间:2023-12-02 05:36:58 26 4
gpt4 key购买 nike

这是我写的

select ISNULL((select convert(bit, null) ), -1)

并预期 -1 结果却得到了 1 ....为什么?我猜是因为那一点,但为什么呢?

如果位域为 NULL,我如何从位域中获取 -1

最佳答案

Bit 只能是 0,1 和 NULL

另外 0 为假,其他均为真。

查看结果

SQL Fiddle DEMO

select ISNULL((select convert(bit, null) ), -1) Returns1;
select ISNULL((select convert(bit, null) ), 1) Returns1;
select ISNULL((select convert(bit, null) ), 100) GuessWhat_Returns1;
select ISNULL((select convert(bit, null) ), 0) Returns0;

最重要的部分

来自 bit (Transact-SQL)

Converting to bit promotes any nonzero value to 1.

关于sql - 从 SQL 中的位字段获取 -1,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22670702/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com