Solved

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

Posted on 2009-05-08
2
163 Views
Last Modified: 2012-05-06
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
Comment
Question by:synovacorp
2 Comments
 
LVL 75

Accepted Solution

by:
Aneesh Retnakaran earned 500 total points
ID: 24335998
INSERT INTO smi_Status(DateStamp,TABLENAME,TABLEUID,STATUS)
SELECT Current_TimeStamp,'TicketPoolHist',i.Identity_Column,1
FROM Inserted i

0
 

Author Closing Comment

by:synovacorp
ID: 31579436
Worked perfect.
Many Thanks.
Brian
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

PL/SQL can be a very powerful tool for working directly with database tables. Being able to loop will allow you to perform more complex operations, but can be a little tricky to write correctly. This article will provide examples of basic loops alon…
Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
This video discusses moving either the default database or any database to a new volume.

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now