How can i use variables in "update" statments ?

How can i use variables in "update" statments ?

am 21.07.2005 10:49:30 von ROMEO PETRUCA

set @month='05';
set @year='2005';
set @table=concat('table',@month,@year);

and i want this:

update table052005 set........

but something like this

update @table set.........

some answers ???

Romeo Petruca
George Enescu 16/13
Hunedoara
0720301842

__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com

--
MySQL Windows Mailing List
For list archives: http://lists.mysql.com/win32
To unsubscribe: http://lists.mysql.com/win32?unsub=gcdmw-win32@m.gmane.org

Re: How can i use variables in "update" statments ?

am 21.07.2005 14:22:54 von Petr Vileta

I'm using MySQL 3.23.xx but IMHO this is the same in last versions...
User variables may NOT be used for what you want. You must create suitable
SQL command before you call MySQL, eg. in PHP, Perl, Visual Basic etc.

For example my rutine in Perl for deleting all old recors from all tables:

my $tables=();
$sth=$dbh->do("use test_database");

# get all table names
$sth=$dbh->prepare("show tables");
$sth->execute() or die "no execute";
while($row = $sth->fetchrow_arrayref)
{
# add table name to end of array $tables
$tables[$#tables+1]=$row->[0];
}

#delete all rows where insert_date < now() from all tables
foreach my $table(0..$#tables)
{
$sth->prepare("delete from $table where insert_date < now()");
$sth->execute() or print "no deleted from $table\n";
}
$sth->finish;



Petr Vileta, Czech republic
(My server reject all messages from Yahoo and Hotmail. Send me your mail
from another non-spammer site please.)




----- Original Message -----
From: "ROMEO PETRUCA"
To:
Sent: Thursday, July 21, 2005 10:49 AM
Subject: How can i use variables in 'update' statments ?


> set @month='05';
> set @year='2005';
> set @table=concat('table',@month,@year);
>
> and i want this:
>
> update table052005 set........
>
> but something like this
>
> update @table set.........
>
> some answers ???
>
> Romeo Petruca
> George Enescu 16/13
> Hunedoara
> 0720301842
>
> __________________________________________________
> Do You Yahoo!?
> Tired of spam? Yahoo! Mail has the best spam protection around
> http://mail.yahoo.com
>
> --
> MySQL Windows Mailing List
> For list archives: http://lists.mysql.com/win32
> To unsubscribe: http://lists.mysql.com/win32?unsub=petr@practisoft.cz
>


--
MySQL Windows Mailing List
For list archives: http://lists.mysql.com/win32
To unsubscribe: http://lists.mysql.com/win32?unsub=gcdmw-win32@m.gmane.org