Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 trigger multiple insert where is where 1,3 and 2,3

Author  Topic 

programer
Posting Yak Master

221 Posts

Posted - 2013-09-18 : 08:52:33
Hello,

i need multiple insert with different where.

My trigger:
ALTER TRIGGER [dbo].[BetSlipEventsTrigger]
ON [dbo].[tbl_BetSlipEvents]
AFTER INSERT,
UPDATE,
DELETE
AS

SET NOCOUNT ON;

WITH cteSource(ID, rn)
AS (
SELECT ID,
ROW_NUMBER() OVER (ORDER BY ID) AS rn
FROM inserted
)
MERGE dbo.tbl_BetSlipSystem AS tgt
USING (
SELECT ID
FROM cteSource
WHERE rn IN (1, 3)
) AS src ON src.ID = tgt.BetSlipEventID
WHEN NOT MATCHED BY TARGET
THEN INSERT (
BetSlipEventID
)
VALUES (
src.ID
)
WHEN NOT MATCHED BY SOURCE
THEN DELETE;


This is works but I want to insert where is 1,3
SELECT ID
FROM cteSource
WHERE rn IN (1, 3)

HEN NOT MATCHED BY TARGET
THEN INSERT (
BetSlipEventID
)
VALUES (
src.ID

It's ok.

And then I want to insert where is 2,3
SELECT ID
FROM cteSource
WHERE rn IN (2, 3)

HEN NOT MATCHED BY TARGET
THEN INSERT (
BetSlipEventID
)
VALUES (
src.ID

pls help
   

- Advertisement -