I try to update / insert ... I get an error: (Msg 8672, Level 16, State 1, Line 1 The MERGE statement tried to UPDATE or DELETE the same line more than once. This happens when the target line matches more than one source row. The MERGE statement cannot update / delete the same row of the target table several times. Refine the ON clause to ensure that the target row matches at most one source row, or use the GROUP BY clause to group the source rows.)
Merge into Rows as R USING (select RowNo,DOB,Pin,State,RowType,RowStatus from Temp_info) as tmp ON R.Rownumber=tmp.Rowno WHEN MATCHED THEN UPDATE SET R.DOB=tmp.DOB, R.Pin=tmp.Pin, R.State=tmp.State, R.RowType=tmp.RowType, R.RowStatus=tmp.RowStatus, R.deleted='N', R.last_modified=getdate() WHEN NOT MATCHED THEN INSERT (RowNumber,DOB,Pin,State,RowType,RowStatus,deleted,last_modified) values (tmp.RowNo,tmp.DOB,tmp.Pin,tmp.State,tmp.RowType,tmp.RowStatus,'N',GETDATE());
source share