-1

Using SQL Server 2016, I have one row in a table, and I am trying to craft a query to select the primary key from that row, based on two columns.

I know the information in the row, but when I include the info in the where clause it still doesn't find anything. Below is the screenshot showing the row and the query. The query returns nothing.

I also tried using the & operator, and I tried putting the 22 in '' and (). The finished column is datatype binary(50), and the DoorNum column is datatype int.

enter image description here

select * 
from Dropoff 
where finished = NULL 
  and DoorNum = 22;
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Josh Eblin
  • 95
  • 1
  • 9

4 Answers4

4

Do not use "=" for NULL values. Because nothing equals NULL, not even NULL. NULL means "Unknown"... if you can't know what's in it, you can't compare them.

Change your query to this:

select * from Dropoff 
where finished IS NULL and 
      DoorNum = 22;
pmbAustin
  • 3,890
  • 1
  • 22
  • 33
3

I think it "is null" to check null values as below:

select * from Dropoff 
where finished is NULL and 
  DoorNum = 22;
Kannan Kandasamy
  • 13,405
  • 3
  • 25
  • 38
2

Use IS NULL instead as next:-

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

Follow These:-

SQL is null and = null

what is “=null” and “ IS NULL”

Is there any difference between IS NULL and =NULL

Community
  • 1
  • 1
ahmed abdelqader
  • 3,409
  • 17
  • 36
1

You shoud use Is Null instead:

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

Use Is Null to determines whether a specified expression/Value is NULL.

Ilyes
  • 14,640
  • 4
  • 29
  • 55