I'm trying to figure out how to insert into an existing table (tbl01) from a temporary table (temp) where the records do not already exist in the existing table (tbl01). I hope that makes sense. I'm basically, trying to update a table with records that have occurred since the last update of the table. Here's my code so far:
insert into tbl01
(sale_store, sale_dt, sale_register, sale_trans)
select distinct
sale_store, sale_dt, sale_register, sale_trans
from temp
where NOT EXISTS (select * from tbl01)
The issue that I'm having is that it runs, but does not put any new records into the table - there should be be lots of new records. I'm sure it's something small and stupid I'm missing. I used this post as my guide: How to avoid duplicates in INSERT INTO SELECT query in SQL Server?
Thank you in advance!