?
Solved

Triggers

Posted on 1998-08-04
2
Medium Priority
?
352 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 400 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

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

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

Why is this different from all of the other step by step guides?  Because I make a living as a DBA and not as a writer and I lived through this experience. Defining the name: When I talk to people they say different names on this subject stuff l…
JSON is being used more and more, besides XML, and you surely wanted to parse the data out into SQL instead of doing it in some Javascript. The below function in SQL Server can do the job for you, returning a quick table with the parsed data.
Via a live example, show how to setup several different housekeeping processes for a SQL Server.
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.
Suggested Courses

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