I have 2 tables with the same schema, one is just a table that data gets bulk loaded into and the other is my live table. I want to update the live table from the uploaded table where the rows are different. I think I am pretty close here but where would my UPDATE actually come into play?
This gives me my updated rows that actually have changes I want to push into my live table:
SELECT USC.* FROM UpdateStagingCustomers AS USC
JOIN StagingCustomers AS SC
ON USC.CustomerNumber = SC.CustomerNumber
AND USC.ManufacturerID = SC.ManufacturerID
WHERE USC.ManufacturerID=18 AND SC.ManufacturerID = 18
AND USC.CustomerNumber IN(
SELECT CustomerNumber FROM StagingCustomers WHERE ManufacturerID=18
)
AND
(
USC.Address1 <> SC.Address1 OR
USC.Address2 <> SC.Address2 OR
USC.AuthorizedDealer <> SC.AuthorizedDealer OR
USC.City <> SC.City
)
I believe this SQL Statement will do the job, but you might want to test it in a rolled back transaction.