title: Merge Statement Error debugging
body: <p>I have a situation where I have a store procedure that contains a merge statement. The procedure grabs data from table A and uses the merge statement to update certain records in table B. The procedure works fine but occasionally, there are instances where there are duplicate records in table A. The store procedure is in a package with error notification set up and the package runs in a job and it gives the error below. Are there any ways that we can debug this? Like some where in the store procedure say if it gives an error then insert the source data into a table? Any input is appreciated.</p>
  
  <p>Thanks</p>
  
  <p>Error :</p>
  
  <blockquote>
    <p>failed with the following error: "The MERGE statement attempted to
    UPDATE or DELETE the same row more than once. This happens when a
    target row matches more than one source row. A MERGE statement cannot
    UPDATE/DELETE the same row of the target table multiple times. Refine
    the ON clause to ensure a target row matches at most one source row,
    or use the GROUP BY clause to group the source rows.". Possible
    failure reasons: Problems with the query, "ResultSet" property not set
    correctly, parameters not set correctly, or connection not established
    correctly.</p>
  </blockquote>