Trigger Code

Results 1 to 3 of 3

Thread: Trigger Code

  1. #1
    Mauricio C. Guest

    Default Trigger Code

    &nbsp;<BR>Hello all, I&#039ve been looking for trigger code, but I&#039m haven&#039t been able to find anything else than troubleshooting. <BR><BR><BR> I&#039m trying to make a trigger that&#039ll fire an stored procedure everytime a table is updated. BUT only if a specific column is changed into a specific value.<BR><BR>E.G. let&#039s say I&#039m working on a project about soccer.. so I have a table named MATCHES (with a local team ID, and a visitor team ID and final score AND STATUS) if the status is notPlayed, then no prob.<BR><BR><BR>But once the status is changed from notPlayed to Played, I need to sum up the finalScore and insert it into another table. <BR>How do I go about it? <BR><BR><BR><BR>Thanks a lot!<BR><BR><BR><BR>(inserting is part of the stored procedure, not the trigger!)

  2. #2
    Join Date
    Dec 1969
    Los Angeles, CA

    Default RE: Trigger Code

    create trigger trigName<BR>on test<BR>for update, insert<BR>as<BR>declare @coulmnValue<BR>if update(status) -- if status is updated<BR>begin<BR>select @coulmnValue = status from inserted --select the value from the table for that row<BR>if @coulmnValue = &#039Played&#039 -- check what was entered/updated<BR>begin<BR>--here you do your update or insert statement<BR>end<BR>end<BR>

  3. #3
    Mauricio C. Guest

    Default RE: Trigger Code -- THANKS

    Thanks a lot, I made a little adjustments, but it worked. I had to change the &#060;i&#062;status from inserted&#060;/i&#062; TO &#060;i&#062;status from updated&#060;/i&#062; <BR><BR><BR>Thanks a lot, and happy new year.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts