baperl has asked for the wisdom of the Perl Monks concerning the following question:

I am working with the INSERT code in Perl, which was initially:
my $in_rec="INSERT INTO $table (name,trans_date,price) VALUES(\'$name\ +',\'$dt\',\'$prc\');"; my $sth=$dbh->prepare($in_rec);
this inserted NULL into date, so I rewrote it as:
my $tdt="select str_to_date(\'$dt\','%m/%d/%Y');"; my $in_rec="INSERT INTO $table (name,trans_date,price) VALUES(\'$name\ +',\'$tdt\',\'$prc\');"; my $sth=$dbh->prepare($in_rec);
but then I get the following error:
DBD::mysql::st execute failed: You have an error in your SQL syntax; c +heck the manual that corresponds to your MySQL server version for the + right syntax to use near '07/29/2011','%m/%d/%Y');','30.53')' at lin +e 1 at test.pl line 34. SQL error:$DBI::errstr
is there a way I can include the STR_TO_DATE within my INSERT statement itself? can you please help me fix this...thanks!

Replies are listed 'Best First'.
Re: STR_TO_DATE in Perl code
by Anonymous Monk on Jul 31, 2011 at 21:27 UTC
      thanks....that worked!