Reputation: 8990
I have a basic select query that is pulling in the results of a queue to our page. I am trying to add in some logic to the where
clause that prevents records from showing when they contain a specific set of values.
WHERE (
(L.requestType <> 'Check')
AND (L.requestStatus <> 'New Request')
AND (DATEDIFF(hour, CAST(L.requestDate AS DATE), GETDATE()) between 0 and 48)
)
In the example above, I don't want to include records that have all three data points.
When doing some testing, it is excluding All "Checks" for example even though those records do not also meet the other two pieces of criteria.
How can I go about making my where
clause meet all criteria and not do what appears to be an or
?
Upvotes: 2
Views: 1206
Reputation: 49270
You need
WHERE NOT (L.requestType = 'Check'
AND L.requestStatus = 'New Request'
AND (DATEDIFF(hour, CAST(L.requestDate AS DATE), GETDATE()) between 0 and 48
)
which is equivalent to
WHERE (L.requestType <> 'Check'
OR L.requestStatus <> 'New Request'
OR DATEDIFF(hour, CAST(L.requestDate AS DATE), GETDATE()) not between 0 and 48
)
Upvotes: 5