Thanks Mac.
I have tried as you recommended:
my($now) = time();
my($transaction) = $dbh->prepare("INSERT into PRUEBAS(CODIGO, VALOR,
FECHA) VALUES(?, ?, CONVERT(datetime, ?))");
$transaction->bind_param(1, '10101', {TYPE => SQL_CHAR});
$transaction->bind_param(2, '20202', {TYPE => SQL_CHAR});
$transaction->bind_param(3, '$now', {TYPE => SQL_CHAR});
$transaction->execute;
But it fails with next error message:
DBD::ODBC::st execute failed: [unixODBC] Msg 241, Level 16, State 1,
Server PROSDK01, Line 1
Syntax error converting datetime from character string.
(SQL-HY000)(DBD: st_execute/SQLExecute err=-1) at
./sapp_load_tarificacion_v1.0.0.pl line 118.
Which could be the problem?
Thanks for your help.
Fernando
-----Mensaje original-----
De: Michael A Chase [mailto:[EMAIL PROTECTED]
Enviado el: lunes, 24 de marzo de 2003 14:20
Para: Illera, Fernando; [EMAIL PROTECTED]
Asunto: Re: Problem when insert date value in SQL Server
On Mon, 24 Mar 2003 13:18:58 +0100 "Illera, Fernando"
<[EMAIL PROTECTED]> wrote:
> I'm trying to insert date type values in SQL Server 7.0, but I always
> get the next error:
>
> DBD::ODBC::st execute failed: [unixODBC] Msg 8115, Level 16, State 2,
> Server PROSDK01, Line 1
>
> The table in SQL Server is defined as:
> create table pruebas (char codigo not null, char valor not null,
> datetime fecha null);
>
> I use the next perl code :
>
> my($dbh) = DBI->connect ("dbi:ODBC(RaiseError=>1, Taint=>1,
> AutoCommint=>1):DSN=<DSN>", "user", "pwd");
>
> my($transaction) = $dbh->prepare("INSERT into PRUEBAS(CODIGO, VALOR,
> FECHA) VALUES(?, ?, CONVERT(datetime, $now)");
Is the value in $now properly quoted? If possible, it would be better
to use a VARCHAR or CHAR placeholder in that location. Make sure the
string is properly formatted for CONVERT() to convert.
> $transaction->bind_param(1, '10101', {TYPE => SQL_CHAR});
> $transaction->bind_param(2, '20202', {TYPE => SQL_CHAR});
> $transaction->execute;
>
> I have also tried with:
>
> my($transaction) = $dbh->prepare("INSERT into PRUEBAS(CODIGO, VALOR,
> FECHA) VALUES(?, ?, ?)");
> $transaction->bind_param(1, '10101', {TYPE => SQL_CHAR});
> $transaction->bind_param(2, '20202', {TYPE => SQL_CHAR});
> $transaction->bind_param(3, $now, {TYPE => SQL_TYPE_TIMESTAMP});
> $transaction->execute;
This might work better with the CONVERT() function as in the first
example, but with a VARCHAR or CHAR placeholder where the $now value
goes.
> Perl version is 5.8, DBI version is 1.34 and DBD::ODBC version is
1.05.
> ODBC Driver is freeTDS v0.61.
> OS from I have running perl is Linux Red Hat 7.3
--
Mac :})
** I normally forward private questions to the appropriate mail list. **
Ask Smarter: http://www.catb.org/~esr/faqs/smart-questions.html
Give a hobbit a fish and he eats fish for a day.
Give a hobbit a ring and he eats fish for an age.