MySQL Forums
Forum List  »  Triggers

Creating a trigger statement
Posted by: Benjamin Nkansah
Date: November 04, 2013 06:35AM

drop trigger if exists update_asset;
drop trigger if exists insert_asset;
drop trigger if exists process_asset;

delimiter |
create procedure process_asset_calc
(
in name varchar(50),
in cost decimal(20,2),
in life int(11),
in whenacquired date,
inout Months_Depreciated int(11),
inout Accumulated_Value double(2,0),
in residual_value double(2,0),
inout Monthly_Depreciation double(2,0))
BEGIN
set Months_Depreciated = (YEAR( NOW() * 12 + Month(NOW())) - (YEAR(whenacquired) * 12) +Month(whenacquired);
set Monthly_Depreciation = (cost / life) * residual_value;
set Accumulated_Value = Months_Depreciated * Monthly_Depreciation;
END|
CREATE TRIGGER `update_asset`
before update ON `asset`
for each row
BEGIN
call process_asset_calc(new.name,new.cost,new.life,new.residual_value,new.whenacquired,new.Accumulated_Value,new.Monthly_Depreciation, new.Months_Depreciated);
END|
CREATE TRIGGER `insert_asset`
before insert ON `asset`
for each row
BEGIN
call process_asset_calc(new.name,new.cost,new.life,new.residual_value,new.whenacquired,new.Accumulated_Value,new.Monthly_Depreciation, new.Months_Depreciated);
END|


delimiter ;

when i run this code it gives me this error "#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ';
set Monthly_Depreciation = (cost / life) * residual_value;
set Accumulated_Val' at line 12". and i can't seem to get what it means. Please any help clearing this error will be appreciated. thanks

Options: ReplyQuote


Subject
Views
Written By
Posted
Creating a trigger statement
2030
November 04, 2013 06:35AM
997
November 04, 2013 07:20AM
1137
November 04, 2013 09:21AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.