I
iain
I'm trying to update 19th century dates in SQL Server.
It works fine with dates on or after 1 Jan 1900, but not before. It is also
OK if the 19th century dates are included as literals in the SQL INSERT or
UPDATE command (with $dbh->do or prepare/execute)
Error message: DBD::ODBC::st execute failed: [Microsoft][ODBC SQL Server
Driver]Datetime field overflow (SQL-22008)(DBD: st_execute/SQLExecute
err=-1) at Pat_DOB_error_report.pl line 13.
I've tried all kinds of options like bind_param, SQL_DATE, CAST(? as
datetime). It seems to be interpreted as a date, but the actual year is not
being processed correctly.
I'm not sure if this is a SQL Server or DBD::ODBC issue. I am using recent
versions of everything.
Any ideas for correction or workaround?
Example, using a table called Patients, which has a field called DOB, type
datetime.....
use DBI;
use strict;
my $dbserver="Myserver"; my $dbdatabase="MyDB"; my $dbWinAuth=1;
my $dsn="driver={SQL
Server};SERVER=$dbserver;DATABASE=$dbdatabase;trusted_connection=yes";
my $dbh = DBI->connect("dbi:ODBC:$dsn") or die "cannot connect to database:
$DBI::errstr \n";
$dbh->{AutoCommit}=1;
my $sth = $dbh->prepare("update Patients set DOB=? where PatientID=10");
$sth->execute('1900-01-01'); # works OK
$sth->execute('1799-12-31'); # gives error
It works fine with dates on or after 1 Jan 1900, but not before. It is also
OK if the 19th century dates are included as literals in the SQL INSERT or
UPDATE command (with $dbh->do or prepare/execute)
Error message: DBD::ODBC::st execute failed: [Microsoft][ODBC SQL Server
Driver]Datetime field overflow (SQL-22008)(DBD: st_execute/SQLExecute
err=-1) at Pat_DOB_error_report.pl line 13.
I've tried all kinds of options like bind_param, SQL_DATE, CAST(? as
datetime). It seems to be interpreted as a date, but the actual year is not
being processed correctly.
I'm not sure if this is a SQL Server or DBD::ODBC issue. I am using recent
versions of everything.
Any ideas for correction or workaround?
Example, using a table called Patients, which has a field called DOB, type
datetime.....
use DBI;
use strict;
my $dbserver="Myserver"; my $dbdatabase="MyDB"; my $dbWinAuth=1;
my $dsn="driver={SQL
Server};SERVER=$dbserver;DATABASE=$dbdatabase;trusted_connection=yes";
my $dbh = DBI->connect("dbi:ODBC:$dsn") or die "cannot connect to database:
$DBI::errstr \n";
$dbh->{AutoCommit}=1;
my $sth = $dbh->prepare("update Patients set DOB=? where PatientID=10");
$sth->execute('1900-01-01'); # works OK
$sth->execute('1799-12-31'); # gives error