In the statement below, I’m trying to normalize LocationIDs in the table ‘Replies’ based off the data I retrieve from the subquery SELECT statement. Basically, there are LocationIDs in the Replies table that are not in the MasterList, I would like to replace those occurances with the location of ‘1234’. I figured the statement below would work, but it doesn’t. When I attempt to run it, it updates all the LocationID’s in the Replies tables after May 5th, 2010.
UPDATE Replies
SET Replies.LocationID = '1234'
FROM (SELECT lml.LocationID FROM Replies sfs LEFT JOIN MasterList lml ON lml.LocationID=sfs.LocationID WHERE sfs.CreateDate >= '5/5/2010') AS rs
WHERE rs.LocationID is null
You can use the not exists clause to find locations that do not exists on masterList as