I have a Staging Data Extension that gets records imported into daily. This import brings in new records and updated records. The caveat is the import will bring in identical records from the previous day. A record will be included for 2 days (identical data) in the case of a failed import.
I need to take the records from the Staging Data Extension into a Master Data Extension. I only want to bring in records that are new (don't exist in Master) or Updated records (records that are in Master but have a different value in a field in the Staging DE). I don't want to bring in records from Staging that are identical to Master.
I wrote a Query using a LEFT JOIN and it appears to work as desired. I'm not a SQL guru so I was hoping to get a second set of eyes on this to see if I'm missing something. There are more fields than the sample below I removed most for brevity. I will also need to compare a Source and Destination field to reset a date field to the current date.
--NEW/UPDATED RECORDS FROM Source TO Destination SELECT s.[ID] ,s.[FirstName] ,s.[LastName] ,s.[Result] ,CASE WHEN ISNULL(s.[Result],'') != ISNULL(d.[Result],'') THEN GETDATE() ELSE NULL END AS [StartDate] FROM [dbo].[Source] s LEFT JOIN [dbo].[Destination] d ON d.[ID] = s.[ID] AND ISNULL(d.[FirstName],'') = ISNULL(s.[FirstName],'') AND ISNULL(d.[LastName],'') = ISNULL(s.[LastName],'') AND ISNULL(d.[Result],'') = ISNULL(s.[Result],'') WHERE d.[ID] IS NULL