Domanda

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

È stato utile?

Soluzione

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;
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top