My script is using the merge statement for a few days, every day, but stopped working on October 6. Given and throwing an error:
Message 8672, Level 16, State 1, Line 1
Attempted to update or delete more than one row in a statement of this statement. This happens when a target line matches more than one source line. A merge statement can not be upgraded / deleted several times on the same table of the target table. To ensure a goal line match in most of a source line, or refine the O segment on using the GROUP BY section to group the section rows.
My script looks like this:
dbo.energydata target.webmeterID = source.webmeterID and target.DateTime = source.DateTime As a source, the goal of using the dbo.temp_energydata source as the target is to update target.kWh = source.kWh when the target was not matched then INSERT (WebmeterID, Datetime, KWH) value (source.webmeter ID, source. Datetime, source.kHH);
It basically takes data from a temp_table (temp_energydata) and merges it with the main table (energy data). This uses the merge because the temporary table contains duplicate data every day, and MERGE
prevents duplication errors.
I think I have to provide more information, so if you can tell me to debug this, then it would be good.
You have duplicate entries for your temp table
to get those duplicates Run this query
select the Webmeter ID, count [mm] by Webmaster ID, [DateTime] by dbo.temp_energydata group (*) & gt; 1
Comments
Post a Comment