How can I add ‘DOES NOT EXIST’ to my SQL query?
I need to insert a new row from temp table (temp) if it does not exist in table (t). The problem I have is that there is not a primary key and the temp table is truncated each time its imported. I am merging the data from temp to t with a stored procedure but I only want to import rows that do not exist. I have tried at the start of the insert query:
–IF NOT EXISTS (SELECT * FROM FPS.Predictive_Acquisition_Cost_NEW sa LEFT JOIN FPS_LZ.FPS.Predictive_Acquisition_Cost lz ON lz.Drug_Identifier = sa.Drug_Identifier WHERE sa.Drug_Identifier = lz.Drug_Identifier AND lz.Effective_Date <> sa.Effective_Date)
and at the end of the insert query:
-WHERE NOT EXISTS(SELECT * FROM FPS.Predictive_Acquisition_Cost_NEW)