ms sql 2005 trigger

2010-07-14 Thread Morchella Deliciosa

hey guys. i am trying to get a simple trigger to work.
if i update a field then it sets the corresponding fields with a date.
but the code below when u update the field it then updates ALL fields in table 
with said date.

i am sure i just need to pass the pkey as a @var to a where clause.
but i am not sure how.



CREATE TRIGGER trig_Update_Waive_Date

ON customer
FOR UPDATE 
AS

IF UPDATE(waive)
BEGIN
IF @@ROWCOUNT = 0
UPDATE customer
SET waive_date = getdate()
ELSE
ROLLBACK TRANSACTION
END 

~|
Order the Adobe Coldfusion Anthology now!
http://www.amazon.com/Adobe-Coldfusion-Anthology-Michael-Dinowitz/dp/1430272155/?tag=houseoffusion
Archive: 
http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:335374
Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm
Unsubscribe: http://www.houseoffusion.com/groups/cf-talk/unsubscribe.cfm


Re: ms sql 2005 trigger

2010-07-14 Thread Morchella Deliciosa

got it...
gerr...

CREATE TRIGGER trig_Update_Waive_Date

ON customer
FOR UPDATE 
AS

IF UPDATE(waive)
BEGIN
UPDATE customer
SET waive_date = getdate()
where pkey=(Select pkey from Inserted)
END 

~|
Order the Adobe Coldfusion Anthology now!
http://www.amazon.com/Adobe-Coldfusion-Anthology-Michael-Dinowitz/dp/1430272155/?tag=houseoffusion
Archive: 
http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:335376
Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm
Unsubscribe: http://www.houseoffusion.com/groups/cf-talk/unsubscribe.cfm