SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Creating triggers


Creating triggers

Author
Message
Tammy Robinson
Tammy Robinson
SSC Journeyman
SSC Journeyman (79 reputation)SSC Journeyman (79 reputation)SSC Journeyman (79 reputation)SSC Journeyman (79 reputation)SSC Journeyman (79 reputation)SSC Journeyman (79 reputation)SSC Journeyman (79 reputation)SSC Journeyman (79 reputation)

Group: General Forum Members
Points: 79 Visits: 37
I need a little help with creating trigger. I am trying to update a particular field in one table after a change is made to a field in another table.

Here is the scenario:

A user will update a field;this field will become a null value. At this point, I would like a field in another table to become blank.

I think my issue is that the table that is being updated by the user does not directly link to the table being updated after the trigger.

Here is what I have:

CREATE TRIGGER reset_Assign
ON 1sttable FOR UPDATE
AS

Begin

IF update(hCurrentCamRule) /*field from 1sttable */
IF NULL = (Select i.hCurrentCamRule From inserted i)
IF 'Garage' = (Select i.sDesc from Inserted i)
IF Exists (Select * from 2ndtable b Inner join inserted i2 on i2.hCurrentCamRule = b.hMy
join 3rdtable c on c.hCode = b.htenant)
UPDATE 3rdtable set sfield = ''
From 3rdtable c2 Join 2ndtable b2 on c2.hCode = b2.htenant join inserted i3 on i3.hCurrentCamRule = b2.hMy

END

Any help would be appreciated.

Thanks!
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search