Hello all,I have a stored procedure that I have created that will compare two tables and either insert new records from one to the other, update the records with current values, or delete records that no longer exist.However, I am having an issue with the insert statement inserting duplicate records and the update statement is creating a new ID instead of comparing the IDs and updating that record.Here is the stored procedure:CREATE PROC [dbo].[sp_CheckFileInfo]ASBEGINSET NOCOUNT ONINSERT INTO FileInfo(FileInfoID, FileName, DateCreated, DateModified, FileSize, FullPath, FlagID) Select FileInfoID, FileName, DateCreated, DateModified, FileSize, FullPath, FlagID From Temp_FileInfo Where NOT EXISTS (select 1 from FileInfo F where F.FileInfoID = Temp_FileInfo.FileInfoID)Merge FileInfo AS fUsing Temp_FileInfo As tON f.FullPath = t.FullPathWhen Matched AND f.FileName <> t.FileName ORf.DateModified <> t.DateModified ORf.FileSize <>t.FileSize ORf.FullPath <> t.FullPathThen UpdateSet f.FileInfoID = t.FileInfoID,f.FileName = t.FileName,f.DateCreated = t.DateCreated,f.DateModified = t.DateModified,f.FileSize = t.FileSize,f.FullPath = t.FullPath,f.FlagID = 2;END
Any help would be greatly appreciated.Thanks,Matt