Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    Sep 2013
    Location
    Accra,Ghana
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Creating a trigger statement

    Code:
    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

  • #2
    Super Moderator guelphdad's Avatar
    Join Date
    Mar 2006
    Location
    St. Catharines, Ontario Canada
    Posts
    2,634
    Thanks
    4
    Thanked 148 Times in 139 Posts
    In this line:
    Code:
    set Months_Depreciated = (YEAR( NOW() * 12 + Month(NOW())) - (YEAR(whenacquired) * 12) +Month(whenacquired);
    you have a mis-matched number of braces, eight ( and only seven )


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •