Create column names as Dates dynamically

Database
The Teradata Database channel includes discussions around advanced Teradata features such as high-performance parallel database technology, the optimizer, mixed workload management solutions, and other related technologies.

Create column names as Dates dynamically

Can we make a column name as current_Date value like below ? And these column names are not fixed, they change every month. Any suggestion is greatly appreciated.

I am using Teradata version 14.10. 

 

1/1/20181/2/20181/3/2018
1232323421
423443144
7868762434

 

Tags (1)
1 REPLY
Senior Apprentice

Re: Create column names as Dates dynamically

Hi,

 

You can give columns the names that you suggest (not sure it's a good idea, but you can do it).

 

If an object name does not follow standard SQL naming conventions then you must include it in double quotes (speech marks) every time you reference it.

 

So the following is valid SQL:

CREATE TABLE t1
("1/1/2018" INTEGER
,"1/2/2018" INTEGER
,"1/3/2018" INTEGER);

And then to read from the table you'd have to use something like:

SELECT "1/1/2018"
  ,"1/2/2018"
FROM t1
WHERE "1/3/2018" > 57;

If your column names are dynamic then you'll have to generate the SQL at run-time, using a stored procedure or scripting code.

 

HTH

Dave

 

 

 

Ward Analytics Ltd - information in motion
www: http://www.ward-analytics.com