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.
Author |
Topic |
programer
Posting Yak Master
221 Posts |
Posted - 2013-09-14 : 14:40:15
|
Hi,I have table tbl_BetSlipEventsId, event202, event1203, event2204, eventandtbl_BetSlipSystemIn the table tbl_BetSlipEvents inserted regarding on row in the tbl_BetSlipEvents tableId, BetSlipEventId73, 20274, 204I need to find row 1 and row 3 in the first table and to insert the second table. |
|
programer
Posting Yak Master
221 Posts |
Posted - 2013-09-14 : 15:27:13
|
quote: Originally posted by programer Hi,I have table tbl_BetSlipEventsId, event202, event1203, event2204, eventandtbl_BetSlipSystemIn the table tbl_BetSlipEvents inserted regarding on row in the tbl_BetSlipEvents tableId, BetSlipEventId73, 20274, 204I need to find row 1 and row 3 in the first table and to insert the second table.
My trigger:ALTER TRIGGER BetSlipEventsTriggerON dbo.tbl_BetSlipEventsAFTER INSERT ASBEGIN INSERT INTO tbl_BetSlipSystem(BetSlipEventId) SELECT Id FROM INSERTED WHERE id =352 ;ENDwhere id=352 works, but I need 1 row and 3 row which was inserted in the table.Please help |
|
|
programer
Posting Yak Master
221 Posts |
Posted - 2013-09-14 : 17:36:09
|
Still I need your help how to select row 1 and 3 and then inserted on other tablequote: Originally posted by programer
quote: Originally posted by programer Hi,I have table tbl_BetSlipEventsId, event202, event1203, event2204, eventandtbl_BetSlipSystemIn the table tbl_BetSlipEvents inserted regarding on row in the tbl_BetSlipEvents tableId, BetSlipEventId73, 20274, 204I need to find row 1 and row 3 in the first table and to insert the second table.
My trigger:ALTER TRIGGER BetSlipEventsTriggerON dbo.tbl_BetSlipEventsAFTER INSERT ASBEGIN INSERT INTO tbl_BetSlipSystem(BetSlipEventId) SELECT Id FROM INSERTED WHERE id =352 ;ENDwhere id=352 works, but I need 1 row and 3 row which was inserted in the table.Please help
|
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2013-09-15 : 23:55:43
|
not really sure what are you trying to do but, to get the 1st and 3rd row, you can use row_number()select *from( select *, rn = row_number() over ( order by somecol ) from sometable) dwhere rn = 1or rn = 3 KH[spoiler]Time is always against us[/spoiler] |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2013-09-17 : 11:49:41
|
[code]ALTER TRIGGER dbo.BetSlipEventsTriggerON dbo.tbl_BetSlipEventsAFTER INSERT, UPDATE, DELETEASSET 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 tgtUSING ( SELECT ID FROM cteSource WHERE rn IN (1, 3) ) AS srcWHEN 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 |
|
|
|
|
|
|
|