//Merge Statement in version(12)
MERGE B AS TARGET
USING A AS SOURCE
ON
(
TARGET.Y_Code=SOURCE.Y_CODE AND TARGET.PROC_CODE=SOURCE.PROC_CODE
)
WHEN MATCHED
THEN
UPDATE
SET
TARGET.Y_CODE=Source.Y_CODE,
TARGET.PROC_CODE=Source.PROC_CODE,
TARGET.L_CODE=Source.L_CODE,
TARGET.L_CARAT=Source.L_CARAT,
TARGET.TYP=Source.TYP
WHEN NOT MATCHED BY TARGET
THEN
INSERT (
[Y_CODE],
[PROC_CODE],
[L_CODE],
[L_CARAT],
[TYP]
)
VALUES
(
Source.Y_CODE,
Source.PROC_CODE,
Source.L_CODE,
Source.L_CARAT,
Source.TYP
);
Select *from a
Select *from b
MERGE B AS TARGET
USING A AS SOURCE
ON
(
TARGET.Y_Code=SOURCE.Y_CODE AND TARGET.PROC_CODE=SOURCE.PROC_CODE
)
WHEN MATCHED
THEN
UPDATE
SET
TARGET.Y_CODE=Source.Y_CODE,
TARGET.PROC_CODE=Source.PROC_CODE,
TARGET.L_CODE=Source.L_CODE,
TARGET.L_CARAT=Source.L_CARAT,
TARGET.TYP=Source.TYP
WHEN NOT MATCHED BY TARGET
THEN
INSERT (
[Y_CODE],
[PROC_CODE],
[L_CODE],
[L_CARAT],
[TYP]
)
VALUES
(
Source.Y_CODE,
Source.PROC_CODE,
Source.L_CODE,
Source.L_CARAT,
Source.TYP
);
Select *from a
Select *from b
No comments:
Post a Comment