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

Recommended Answers

You need to either add or remove one parenthesis.

Jump to Post

All 3 Replies

Missing parenthesis:

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

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  "

You need to either add or remove one parenthesis.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.20 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.