0
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;
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 ')
BEGIN
set Months_Depreciated = (YEAR(NOW() * 12 + Month (NOW())) - YEAR(whenac' at line 12 "

and i can't seem to get what it means. Please any help clearing this error will be appreciated. thanks

2
Contributors
3
Replies
18
Views
4 Years
Discussion Span
Last Post by pritaeas
0

Missing parenthesis:

set Months_Depreciated = 
(
    YEAR
    (
        NOW() * 12 + Month
        (
            NOW()
        )
    ) - YEAR(whenacquired) * 12;
0

i dnt know but it still 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 ')

BEGIN
set Months_Depreciated =
(
  YEAR
( 
NOW() * 12 + Month
(
NOW()
)
) - Y' at line 11  "

Edited by Dani: Formatting fixed

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.