My problem is extremely similar to this: Select rows which are not present in other table
but differs in that I am retrieving data from a view, rather than another table. However, the sub-select query does not return any records and I have omitted the INSERT INTO to test the SELECT query
Here is what I have got so far:
SELECT SourceT.*, DestT.Column1, DestT.Column2
FROM
ViewA SourceT
LEFT OUTER JOIN
TableA DestT
ON
SourceT.Column1 = DestT.Column1 AND
SourceT.Column2 = DestT.Column2 AND
SourceT.Column3 = DestT.Column3 AND
**** EVERYTHING WORKS FINE UNTIL HERE
WHERE
DestT.Column1 = NULL AND
DestT.Column2 = NULL AND
DestT.Column3 = NULL
If I leave out the WHERE conditions, it returns all records from SourceT along with values of NULL for those records not found in DestT - this works fine. When I add in the WHERE clause at the bottom (even on just one condition), it returns zero values.
I can try DestT.Column1 = NULL, or DestT.Column1 <> NULL - still nothing is returned. My query correctly returns NULL values but the WHERE condition does not operate, or does not allow any data through.
Any idea what is happening here? Essentially, I'm trying to insert rows from a View into TableA where they don't already exist, based on a number of conditions.
Thank you