create dynamic table name for each month

Database
Fan

create dynamic table name for each month

Hi everyone,

 

I have a doubt about the statement 'create table'. I need to create a table named whatever_YYYYMM. YYYYMM is obviusly the current YYYY and Month.

 

For example I have a procedure for this month (June) so the is called whatever_201706, but I did it manually. For July the table will be whatever_201707. I need to automatice this procedure.

 

Thanks.

1 REPLY
Teradata Employee

Re: create dynamic table name for each month

You could create a shell script or .bat script to generate a bteq script that creates the table. (Ref. http://community.teradata.com/t5/Database/Aliases-into-BTQ-scripts/m-p/73706%23M30608)

 

You could also create a Stored Procedure that creates the table: the SP can "Select DATE (char(10)) into :today" (where today is declared as a char(10) variable) and then use concatenation of substrings of :today to build the table name.