At 19:00 +0200 3/24/02, Okan CIMEN wrote:
>I am trying to write a script that creates tables via a cronjob but I want
>to name these tables including the current date as a suffix -like
>transections_20020324- . Does anybody know the SQL statement that entegrates
>the table name with the current date?
If you're trying to do it entirely in SQL, you'll have a difficult time,
because table names must be literals. You can't construct them using a
function that returns the current date.
Otherwise, the way you construct the table name will depend on the programming
language you're using. In Perl, you could do something like this:
my ($day, $mon, $year) = (localtime (time ()))[3..5];
my $tbl_name = sprintf ("transactions_%04d%02d%02d", $year+1900, $mon+1, $day);
my $query = ("CREATE TABLE $tbl_name ... rest of definition here...");
>I tried to do it by storing the current_date value at a variable and then
>renaming the table with the variable but it did not work.
>Any help will be appreciated