MySQL Forums
Forum List  »  Triggers

Re: trigger with dynamic column name
Posted by: Peter Brawley
Date: November 02, 2020 10:29AM

SQL with variable column names needs PREPARE, which MySQL doesn't support in Triggers.

The table design isn't optimal---if a date needs to be edited, a difference of a day can require the value to be moved to a different column. Nonsensical. Cumbersome date logic like that belongs in reports, not in table designs.

If you're stuck with that design for the moment, you'll need to write a conditional block to cover all 12 months of the year, eg ...

declare mo tinyint unsigned;
set mo = month( new.order_date );
case mo
  when 1 then ...
...
end case;

Options: ReplyQuote


Subject
Views
Written By
Posted
1453
November 02, 2020 06:29AM
Re: trigger with dynamic column name
800
November 02, 2020 10:29AM


Sorry, you can't reply to this topic. It has been closed.
This forum is currently read only. You can not log in or make any changes. This is a temporary situation.

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.