【问题标题】:SQL Server query not returning expected row [duplicate]SQL Server查询未返回预期的行[重复]
【发布时间】:2017-05-10 17:58:47
【问题描述】:

使用 SQL Server 2016,我在表中有一行,我正在尝试制作一个查询以根据两列从该行中选择主键。

我知道行中的信息,但是当我在 where 子句中包含信息时,它仍然找不到任何东西。下面是显示行和查询的屏幕截图。查询不返回任何内容。

我也尝试使用 & 运算符,并尝试将 22 放在 '' 和 () 中。完成的列是数据类型binary(50)DoorNum 列是数据类型int

select * 
from Dropoff 
where finished = NULL 
  and DoorNum = 22;

【问题讨论】:

    标签: sql-server


    【解决方案1】:

    不要将“=”用于 NULL 值。因为没有什么等于 NULL,甚至 NULL。 NULL 表示“未知”...如果您不知道其中的内容,则无法比较它们。

    将您的查询更改为:

    select * from Dropoff 
    where finished IS NULL and 
          DoorNum = 22;
    

    【讨论】:

      【解决方案2】:

      我认为检查空值如下:

      select * from Dropoff 
      where finished is NULL and 
        DoorNum = 22;
      

      【讨论】:

        【解决方案3】:

        使用IS NULL 代替下一个:-

        select * from Dropoff 
        where finished is NULL and 
        DoorNum = 22;
        

        关注这些:-

        SQL is null and = null

        what is “=null” and “ IS NULL”

        Is there any difference between IS NULL and =NULL

        【讨论】:

          【解决方案4】:

          你应该改用Is Null

          SELECT * 
          FROM Dropoff 
          WHERE finished is NULL and DoorNum = 22;
          

          使用Is Null判断一个指定的表达式/值是否is NULL

          【讨论】:

            猜你喜欢
            • 2018-12-22
            • 2012-10-09
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 2015-05-02
            • 1970-01-01
            • 1970-01-01
            相关资源
            最近更新 更多