• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 177
  • Last Modified:

How do Insert records in TableB based on a Batch insert of Records from TableA on a Trigger?

I'm somewhat new to the use of Triggers in MS SQL. My initial creation only gives me 1 new record in the second table(SMI_STATUS) , regardless of the number of records inserted into
the firts table that fires the trigger (TicketPoolHist).

I've looked at several examples on the web, realizing that I need to do a "set" approach, but I can't seem to put it together. Any suggestions?
Brian
Currrent Trigger , which only works on the last record in the Inserted table is shown below.
CREATE TRIGGER [STLog1] ON [dbo].[TicketPoolHist] 
AFTER INSERT,UPDATE 
AS
 
declare @Datestamp as datetime,
@TableName as Char(20),
@TableUID as Integer,
@Status as Char(1)
 
Select
@TableUID = Identity_Column
 
From Inserted
 
INSERT INTO smi_Status(DateStamp,TABLENAME,TABLEUID,STATUS) VALUES (Current_TimeStamp,'TicketPoolHist',@TableUID,1)

Open in new window

0
synovacorp
Asked:
synovacorp
1 Solution
 
Aneesh RetnakaranDatabase AdministratorCommented:
INSERT INTO smi_Status(DateStamp,TABLENAME,TABLEUID,STATUS)
SELECT Current_TimeStamp,'TicketPoolHist',i.Identity_Column,1
FROM Inserted i

0
 
synovacorpAuthor Commented:
Worked perfect.
Many Thanks.
Brian
0

Featured Post

Become an Android App Developer

Ready to kick start your career in 2018? Learn how to build an Android app in January’s Course of the Month and open the door to new opportunities.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now