Solved

Triggers

Posted on 1998-08-04
2
335 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
  • 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

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

I wrote this interesting script that really help me find jobs or procedures when working in a huge environment. I could I have written it as a Procedure but then I would have to have it on each machine or have a link to a server-related search that …
For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
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…
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.

777 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