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 2005 Forums
 .NET Inside SQL Server (2005)
 stored procedure

Author  Topic 

programer
Posting Yak Master

221 Posts

Posted - 2013-09-14 : 04:37:45
Hello,

I have tbl_BetSlipEvents and tbl_BetSlipSystem

tbl_BetSlipEvents:
Id, Event
127, event1
128, event2
129, event3

tbl_BetSlipSystem
Id, BetSlipEventId
1, 127
2, 128
3, 129

So If I inserted in the tbl_BetSlipEvents I need to insert in the table tbl_BetSlipSystem 127,128,129.

I need with stored procedure.

Please help

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2013-09-15 : 06:36:16
duplicate of

http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=188201

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2013-09-17 : 11:49:48
[code]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 dbo.tbl_BetSlipEvents
)
MERGE dbo.tbl_BetSlipSystem AS tgt
USING (
SELECT ID
FROM cteSource
WHERE rn IN (1, 3)
) AS src
WHEN NOT MATCHED BY TARGET
THEN INSERT (
BetSlipEventID
)
VALUES (
src.ID
)
WHEN NOT MATCHED BY SOURCE
THEN DELETE;[/code]


Microsoft SQL Server MVP, MCT, MCSE, MCSA, MCP, MCITP, MCTS, MCDBA
Go to Top of Page
   

- Advertisement -