MySQL Forums
Forum List  »  General

Re: Dynamic assignment of month based on current date
Posted by: Peter Brawley
Date: April 11, 2022 02:08PM

1 MySQL column names that include illegal characters like hyphens, eg `Apr-22`, are unusable without backticks. Avoid them.

2 I understand` `FC1` becomes `apr22` &c, but I do not understand "based on the current date" at all.

3 "The column names" of what "should change every fiscal month according to the reference table dynamically"?

4 SQL handles queries that require dynamic column names with the PREPARE command, but PREPARE would be awkward, I think, for the task you describe. If it's me, I would want to write such logic in a Turing-complete language that's better suited by design for such string manipulation, eg PHP.

5 If as it appears you are trying to import CSV tables into MySQL where the target table column names vary by the month, the overall strategy should be to use one input table then write a script that massages the DDL and data monthly as desired for the eventual target table.

Options: ReplyQuote

Written By
Re: Dynamic assignment of month based on current date
April 11, 2022 02:08PM

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.