Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
bendertez
Yak Posting Veteran
94 Posts |
Posted - 2012-03-23 : 12:44:52
|
HiI've only just started using triggers so apologies for my lack of knowledge on this area, all i wanted to know if you can fire a trigger on a particular value of a field?I have successfully implemented a trigger below which works when the field is changed which is okay, but I want it only to fire when the status field is 'Registered'. There are other values that it can be but I only want it to fire when the status is 'Registered'CREATE TRIGGER Reset_TimesOutON SupplierFOR UPDATE asIF UPDATE(Status)BEGINUPDATE aSET Renew_Alloc = 0FROM Account a, Deleted d, Inserted iWHERE d.accountid = a.cccountidEND Just to note the update is required on the account table where the status is on the supplier table which have both have an accountid primary key. Can anybody help me on this as i'm sure it must be achievable.Thanks |
|
X002548
Not Just a Number
15586 Posts |
|
X002548
Not Just a Number
15586 Posts |
|
bendertez
Yak Posting Veteran
94 Posts |
Posted - 2012-03-26 : 05:32:10
|
Hi BrettThanks for the reply.I kind of thought that it might be something like what you have written and implementing this seems to work perfectly when the status is set to "Registered" However when I set anything other than "Registered" it falls overs with an error of:"Row cannot be located for updating. Some values may have been changed sinc it was last read."This seems to be a VB error message, but I don't understand why it works when the status is "Registered" but it falls over when it is something elese. I thought from the code that the trigger wouldn't update anything unless the status was "Registered"?Do you have any idea why it is doing this?Thanks |
 |
|
X002548
Not Just a Number
15586 Posts |
|
|
|
|