Solved

Triggers

Posted on 1998-08-04
2
331 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
Comment Utility
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
Comment Utility
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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Suggested Solutions

Everyone has problem when going to load data into Data warehouse (EDW). They all need to confirm that data quality is good but they don't no how to proceed. Microsoft has provided new task within SSIS 2008 called "Data Profiler Task". It solve th…
Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.

762 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now