-- Executing Command:
MERGE INTO [Customers] AS DestinationTable
USING
(
SELECT TOP 100 PERCENT * FROM (SELECT @0_0 AS [CustomerID], @0_1 AS [Description], @0_2 AS [IsActive], @0_3 AS [Name], @0_4 AS ZZZ_Index
UNION ALL SELECT @1_0 AS [CustomerID], @1_1 AS [Description], @1_2 AS [IsActive], @1_3 AS [Name], @1_4 AS ZZZ_Index
UNION ALL SELECT @2_0 AS [CustomerID], @2_1 AS [Description], @2_2 AS [IsActive], @2_3 AS [Name], @2_4 AS ZZZ_Index) AS StagingTable ORDER BY ZZZ_Index
) AS StagingTable
ON DestinationTable.[CustomerID] = StagingTable.[CustomerID]
WHEN MATCHED THEN
UPDATE
SET [Description] = StagingTable.[Description], [IsActive] = StagingTable.[IsActive], [Name] = StagingTable.[Name]
WHEN NOT MATCHED THEN
INSERT ( [Description], [IsActive], [Name] )
VALUES ( [Description], [IsActive], [Name] )
OUTPUT
$action,
StagingTable.ZZZ_Index,
1,
INSERTED.[CustomerID] AS [CustomerID_zzzinserted]
;
-- @0_0: 1 (Type = Int32, Size = 4)
-- @0_1: Description_Customer_A_Updated (Type = String, Size = -1)
-- @0_2: False (Type = Boolean, Size = 1)
-- @0_3: Customer_A_Updated (Type = String, Size = -1)
-- @0_4: 0 (Type = Int32, Size = 0)
-- @1_0: 2 (Type = Int32, Size = 4)
-- @1_1: Description_Customer_B_Updated (Type = String, Size = -1)
-- @1_2: False (Type = Boolean, Size = 1)
-- @1_3: Customer_B_Updated (Type = String, Size = -1)
-- @1_4: 1 (Type = Int32, Size = 0)
-- @2_0: 0 (Type = Int32, Size = 4)
-- @2_1: Description_Customer_C_Inserted (Type = String, Size = -1)
-- @2_2: False (Type = Boolean, Size = 1)
-- @2_3: Customer_C_Inserted (Type = String, Size = -1)
-- @2_4: 2 (Type = Int32, Size = 0)
-- CommandTimeout:0
-- Executing at 05/29/2025 19:11:42
-- Completed at 05/29/2025 19:11:42
-- Result: 3 rows