I am sure making a silly mistake but I can’t figure what:
In SQL Server 2005 I am trying select all customers except those who have made a reservation before 2 AM.
When I run this query:
SELECT idCustomer FROM reservations WHERE idCustomer NOT IN (SELECT distinct idCustomer FROM reservations WHERE DATEPART ( hour, insertDate) < 2)
I get 0 results.
But
SELECT idCustomer FROM reservations
returns 152.000 results and the ‘NOT IN’ part:
SELECT distinct idCustomer FROM reservations WHERE DATEPART ( hour, insertDate) < 2
returns only 284 rows
Make sure your list parameter does not contain null values.
Here’s an explanation:
is the same as:
(*) Edit: this explanation is pretty good, but I wish to address one thing to stave off future nit-picking. (TRUE OR NULL) would evaluate to TRUE. This is relevant if field1 = 3, for example. That TRUE value would be negated to FALSE and the row would be filtered.