Solved

SQL - Pass Value to Trigger

Posted on 2010-11-10
7
607 Views
Last Modified: 2012-08-13
I do not know if this can be done.  I know with a stored procedure it can be accomplished.  I want to know if it can be accomplished with a Trigger.  Ok, lets say there are 3 tables - tableA, tableB, and tableC.   The result is to get data from tableA and tableB into tableC.

I call a stored procedure and in this stored procedure I pass in the values for TableA to perform an insert.  I am also inserting into TableB and getting the ID by SCOPE_IDENTITY.

So lets say I need the following fileds TableA.Name, TableA.Address, and TableC.ResultsID (these tables are not joined in anyway and the value of TableC.ResultsID will be obtained using SCOPE_IDENTITY).

The question is if I put a trigger on TableA to pass the data to TableC --  how do I get the TableC.ResultID data in the Trigger?

Hope this makes sense.
0
Comment
Question by:CipherIS
[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
  • 4
  • 2
7 Comments
 
LVL 9

Expert Comment

by:Philippe Damerval
ID: 34106584
The answer to your question of whether this can be done or not is yes, it can be done and is fairly easy. SCOPE_IDENTITY returns the last ID used in the current scope (current SP, UDF or batch).
The real question I think is what are you trying to achieve? Why are you copying data from one table to another? Once we determine what you want to achieve, we can best recommend how to do it, which may or may not involve launching inserts from inside triggers.

Let us know!

Philippe
0
 
LVL 1

Author Comment

by:CipherIS
ID: 34106726
I am building an alert system.  TableC will contain information for the Alerts.  

Certain fields in TableA (lets say its an employee table) need to be passed to TableC when an insert, update, or delete is performed.  

TableB is a log table.

The requirement is to pass the pkid of TableB to TableC while inserting TableA data into TableC.  

(hope I didn't confuse anyone).
0
 
LVL 1

Accepted Solution

by:
CipherIS earned 0 total points
ID: 34106974
i figured out how to do it.  thx.
0
Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

 
LVL 21

Expert Comment

by:Alpesh Patel
ID: 34110075
You can not pass parameter to Trigger. But you can access the deleted, inserted tables in it.
0
 
LVL 1

Author Comment

by:CipherIS
ID: 34313898
test
0
 
LVL 9

Expert Comment

by:Philippe Damerval
ID: 34313965
It's okay with me, although in the spirit of the experts-exchange community I wish the author would post a brief description of what solution worked for them. It is not clear whether the advice given by experts was useful or not.
Thanks!
0
 
LVL 1

Author Closing Comment

by:CipherIS
ID: 34341638
figured it out
0

Featured Post

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

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

Suggested Solutions

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…
Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

738 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