?
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
Medium Priority
?
173 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 75

Accepted Solution

by:
Aneesh Retnakaran earned 2000 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

Want to be a Web Developer? Get Certified Today!

Enroll in the Certified Web Development Professional course package to learn HTML, Javascript, and PHP. Build a solid foundation to work toward your dream job!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Hopefully the following mnemonic and, ultimately, the acronym it represents is common place to all those reading: Please Excuse My Dear Aunt Sally (PEMDAS). Briefly, though, PEMDAS is used to signify the order of operations (http://en.…
Composite queries are used to retrieve the results from joining multiple queries after applying any filters. UNION, INTERSECT, MINUS, and UNION ALL are some of the operators used to get certain desired results.​
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Suggested Courses

764 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