Baffling query results or lack of...
I am trying to return a record set by excluding records from the set that may already exist in a second table.
SELECT trID
FROM ttTrct
WHERE (trID NOT IN
(SELECT rteVehID
FROM rtHist
WHERE (rteSchedDT = '11/19/2012 12:00:00 AM')))
ORDER BY tractorID
actual where clause is...
WHERE (rteSchedDT = CAST(@targetDate AS DATETIME))
But have been also trying with static date value to avoid any issues there.
Three records exist in rtHist
rteVehID rteSchedDT
NULL 11/12/2012 12:00:00 AM
NULL 11/19/2012 12:00:00 AM
1645 11/19/2012 12:00:00 AM
Five records exist in ttTrct
trID
1234
4567
9874
1645
2442
I am expecting my result set to include 4 records and not 1645. But I only get NULL. Also, If the third record in the rtHist table were also NULL instead of 1645, I also get no results. Of course the static date will eventually be a variable.
Any ideas on what I am missing? thanks in advance. SSEE 2008 R2