Solved

SQL - Pass Value to Trigger

Posted on 2010-11-10
7
609 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
Webinar: Aligning, Automating, Winning

Join Dan Russo, Senior Manager of Operations Intelligence, for an in-depth discussion on how Dealertrack, leading provider of integrated digital solutions for the automotive industry, transformed their DevOps processes to increase collaboration and move with greater velocity.

 
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

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

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

Hi all, It is important and often overlooked to understand “Database properties”. Often we see questions about "log files" or "where is the database" and one of the easiest ways to get general information about your database is to use “Database p…
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…
This video Micro Tutorial shows how to password-protect PDF files with free software. Many software products can do this, such as Adobe Acrobat (but not Adobe Reader), Nuance PaperPort, and Nuance Power PDF, but they are not free products. This vide…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…

724 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