Here's my Trigger code on table [dbo].[tbl_Inventory_Temp]
which is loaded using SQLBulkCopy from ASP.NET app. The Temp table loads and I don't think the Trigger is firing. I'm using a remote db connection and the debugger won't run, not enough permission.
Note: Currently the [dbo].[tbl_Inventory_TEST]
table is empty and I don't know if that effects the 'ON' statement in the Merge below.
Note: It would be nice to have some sort of 'Status' return message if possible to help with errors...
/****** Object: Trigger [dbo].[MergeInventory] Script Date: 10/15/2013 11:58:32 AM ******/
SET ANSI_NULLS ON
SET QUOTED_IDENTIFIER ON
ALTER TRIGGER [dbo].[MergeInventory] ON [dbo].[tbl_Inventory_Temp]
AFTER INSERT AS
SET NOCOUNT ON;
MERGE [dbo].[tbl_Inventory_TEST] AS T
USING [dbo].[tbl_Inventory_Temp] AS S
ON (T.Vin = S.Vin)
WHEN NOT MATCHED BY TARGET
INSERT (StockNumber, Vin, [Year], AddedOn, ModifiedOn)
VALUES (StockNumber, Vin, [Year], GETDATE(), ModifiedOn)
StockNumber = S.StockNumber,
[Year] = S.[Year],
ModifiedOn = GETDATE()
OUTPUT $action, inserted.*, deleted.*;
DELETE WHERE Vin = @Vin;