Hallo zusammen
Ich habe wieder einmal was ganz tolles zum erledigen.
Ausgangslage: Zieltable = A, Target = B
In der Table A habe ich eine Spalte welche Dateninhalt haben, diese Daten möchte ich in die spalte der Table B updaten.
Fehlermeldung:
Msg 8672, Level 16, State 1, Line 3
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.
Table A
IDDateAktion
B1120130101Neu
A2220130203defekt
C1220130103neu
B1120130110keine Funktion
Table B
IDDateAktion
B1120130101NULL
A2220130203NULL
C1220130103NULL
B1120130110NULL
Hier die Query:
Merge dbo.B as T Using (Select ID ,Aktion From dbo.A where Date between '20120101' and '20130331') as S On (T.ID = S.ID) WHEN MATCHED THEN UPDATE SET T.Aktion = S.Aktion Output $action, inserted.*;
Die Option Refin ON habe ich auch nicht. Das Problem könnte ich sicher lösen wenn ich dem beibringen könnte. Die Datensätze Zeile für Zeile durcharbeiten könnte.
Beste Grüsse im Voraus.
Mehmet