MERGE INTO [dbo].[ITEMS] AS TARGET
USING [PRODUCT].[NARO].[dbo].[ITEMS] AS SOURCE
ON (TARGET .Code=SOURCE.Code)
WHEN NOT MATCHED BY TARGET THEN
INSERT (Code, Name, Unit, CreateDateTime, LastEditDateT, Status)
VALUES (SOURCE.Code, SOURCE.Name, SOURCE.Unit, SOURCE.CreateDateTime, SOURCE.LastEditDateT, SOURCE.Status)
WHEN MATCHED THEN
UPDATE SET a.Code=b.Code,
a.Name=b.Name,
a.Unit=b.Unit,
a.CreateDateTime=b.CreateDateTime,
a.LastEditDateT=b.LastEditDateT,
a.Status=b.Status
WHEN NOT MATCHED BY SOURCE
THEN DELETE;
MERGE INTO [dbo].[ITEMS] AS TARGET
USING [PRODUCT].[NARO].[dbo].[ITEMS] AS SOURCE
ON (TARGET .Code=SOURCE.Code)
WHEN NOT MATCHED BY TARGET THEN
INSERT (Code, Name, Unit, CreateDateTime, LastEditDateT, Status)
VALUES (SOURCE.Code, SOURCE.Name, SOURCE.Unit, SOURCE.CreateDateTime, SOURCE.LastEditDateT, SOURCE.Status)
WHEN MATCHED AND b.LastEditDateT > a.LastEditDateT THEN
UPDATE SET a.Code=b.Code,
a.Name=b.Name,
a.Unit=b.Unit,
a.CreateDateTime=b.CreateDateTime,
a.LastEditDateT=b.LastEditDateT,
a.Status=b.Status
WHEN NOT MATCHED BY SOURCE
THEN DELETE;
MERGE INTO [PRODUCT].[NARO].[dbo].[ITEMS] AS TARGET
USING [dbo].[ITEMS] AS SOURCE
ON (TARGET .Code=SOURCE.Code)
WHEN NOT MATCHED BY TARGET THEN
INSERT (Code, Name, Unit, CreateDateTime, LastEditDateT, Status)
VALUES (SOURCE.Code, SOURCE.Name, SOURCE.Unit, SOURCE.CreateDateTime, SOURCE.LastEditDateT, SOURCE.Status)
WHEN MATCHED AND b.LastEditDateT > a.LastEditDateT THEN
UPDATE SET a.Code=b.Code,
a.Name=b.Name,
a.Unit=b.Unit,
a.CreateDateTime=b.CreateDateTime,
a.LastEditDateT=b.LastEditDateT,
a.Status=b.Status
WHEN NOT MATCHED BY SOURCE
THEN DELETE;