Solved

Triggers

Posted on 1998-08-04
2
347 Views
Last Modified: 2010-03-19
Hi, I am trying to create an update trigger and everything is correct except how do I pass variables into a stored procedure that I am calling within a trigger. My example is below:

CREATE TRIGGER master_update_trigger
ON dbo.ksu_master_term_table
FOR UPDATE

AS

if update(hall)
begin
      if exists (select * from restv.dbo.restv_table, inserted where restv.dbo.restv_table.
      client_id=inserted.stud_id and restv.dbo.restv_table.term_code=inserted.term_code
      and  restv.dbo.restv_table.active ="Y")
      begin
      
            update restv.dbo.restv_table set restv.dbo.restv_table.active = "N",
            restv.dbo.restv_table.done = "N",restv.dbo.restv_table.hall=inserted.hall,
            restv.dbo.restv_table.room = inserted.room, restv.dbo.restv_table.local_phone=inserted.
            local_phone From inserted where restv.dbo.restv_table.client_id=inserted.stud_id and
            restv.dbo.restv_table.term_code=inserted.term_code

--------------------------->  exec restv_insert_sp

--------------------------->insert into restv.dbo.restv_table (client_id,hall,room,first_name,last_name,term_code,
            converter_cost,converter_qty,coax_cable_qty,coax_cable_cost,hbo_cost,showtime_cost,
            total_cost,previous_term_code,done,active,date_time_stamp,local_phone,billed,order_num)
            values ("deleted.client_id","deleted.hall","deleted.room","deleted.first_name","deleted.
                  last_name","deleted.term_code","deleted.converter_cost",CONVERT(tinyint,"deleted.converter_qty"),
            CONVERT(tinyint,"deleted.coax_cable_qty"),CONVERT(smallmoney,"deleted.coax_cable_cost"),
            CONVERT(smallmoney,"deleted.hbo_cost"),CONVERT(smallmoney,"deleted.showtime_cost"),
            CONVERT(money,"deleted.total_cost"),"deleted.previous_term_code","deleted.done","deleted.active",
            "getdate()","deleted.local_phone","deleted.billed",CONVERT(int,"deleted.order_num"))
            From deleted where restv.dbo.restv_table.client_id=inserted.stud_id and
            restv.dbo.restv_table.term_code=inserted.term_code
      end      
end


All I am trying to do is to create an update trigger that will update a record in another datebase and will
insert the old record before the update also into another datebase. Can you tell mw what is wrong with my syntax where I am trying to insert the old record after the stored procedure
0
Comment
Question by:kevykev
[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
2 Comments
 
LVL 2

Accepted Solution

by:
jbiswas earned 100 total points
ID: 1089403
To call a stored proc from inside a trigger all you have to do is pass the right parameters to the stored proc. So if the stored proc is expecting two parameters, just call the stored proc with the right parameters inside paranthesis
exec stored_proc(parameterA, parameterB)

That should work.
0
 
LVL 2

Expert Comment

by:jbiswas
ID: 1089404
By the way I do not know of any before update triggers in MS SQL Server..maybe you wanna check whether that is allowed. However I do not see any before or update clause in your code. maybe you're doing so by the stored proc?
0

Featured Post

Business Impact of IT Communications

What are the business impacts of how well businesses communicate during an IT incident? Targeting, speed, and transparency all matter. Find out more in this infographic.

Question has a verified solution.

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

This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.

726 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