Answer the question
In order to leave comments, you need to log in
How to use variable as table name in SELECT?
There is a need to generate a table name depending on the current time, it is formed like this:
"SELECT CONCAT('dbname.tableprefix',DATE_FORMAT(NOW(),'%Y%m')) INTO @tablename;"
Next, you need to execute the query "SELECT `somefield` FROM @tablename;"
MySQL (5.5.44) throws a syntax error.
How to use variable value as table name for query?
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question