Question

I'd like to create a dynamic table name which store the current year and after the table name is it possible? Because i make some summary for a company and its needed to get the current year when the table is made especially now because the next year is coming!

I'll tried the next one but it doesn't work

create table (date_format(curdate(),'%Y')) as  select szallito_nev from beerkezes;

So can i somehow concat the current year with some other words

Était-ce utile?

La solution

You can not do that directly. However, you can use prepared statements:

SET @y = date_format(curdate(),'%Y');
SET @t = CONCAT('create table `', @y, '` as select szallito_nev from beerkezes');
PREPARE stmt FROM @t;
EXECUTE stmtl;

-or, alternatively:

SET @t = CONCAT('create table `', date_format(curdate(),'%Y'), '` as select szallito_nev from beerkezes');
PREPARE stmt FROM @t;
EXECUTE stmtl;
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top