RE: datatype error



-----Original Message-----
From: Craig Metzer [mailto:ucantspamthis@xxxxxxxxxxx]
Sent: Thursday, July 26, 2007 5:36 PM
I'm getting an error trying to run an insert action due to the DATE
or DATETIME datatype. I couldn't find anything on it, and was
wondering
if anyone could point me in the right direction -- Thanks
I'm trying to run an insert ... the date value is giving me errors.
Here's the code:
my $sql = qq{ INSERT INTO perfdata VALUES ( ?, ?, ?, ?, ?, ? ) };
my $sth = $dbh->prepare( $sql );
for ( @record ) {
eval {
$sth->bind_param( 1, @$_->[0], SQL_VARCHAR );
$sth->bind_param( 2, @$_->[1], SQL_VARCHAR );
$sth->bind_param( 3, @$_->[2], SQL_DATETIME );
$sth->bind_param( 4, @$_->[3], SQL_INTEGER );
$sth->bind_param( 5, @$_->[4], SQL_CHAR );
$sth->bind_param( 6, @$_->[5], SQL_VARCHAR );
$sth->execute();
$dbh->commit();
};
if ( $@ ) {
warn "Database error: $DBI::errstr\n";
$dbh->rollback(); #just die if rollback is failing
}
}
$sth->finish();

Perhaps...I'm no expert...you need to use the TO_Date function
and specify the format your string is in.
I have code from an insert process that used the following SQL
statement,
unfortunately the input data file no longer exists so I can't look at
what the format was.
HTH, Paula
(watch out for text wrapping of code by mail client)

sub prepareInsStmt { #set up and prepare the SQL statement
my $seConn = $_[0];
my $stmt1 = 'INSERT INTO SEWEB.logfile ';
my $stmt2 = '(userid, update_ts, category) ';
my $stmt3 = "values (?,TO_Date(?,'YYYY-MM-DD HH24:MI:SS'),?)";
my $stmt = $stmt1.$stmt2.$stmt3;
my $sth = $seConn->prepare( $stmt ) or
processError("PrepareFailed","$stmt",$seConn);
printIt("Insert statement prepared:\n\t$stmt");
return $sth; #return the prepared statement handle
}
This subroutine was called via:
my $isth = prepareInsStmt($seConn); #prepare INSERT w/ placeholder

And the inserts processed via:
while (<HIST>) {
chomp;
my ($uid,$datets,$category,$desc) = split /,/,$_;
$isth->execute($uid,$datets,$category)
or processError("ExecuteFailed",$isth,$seConn);
}
.



Relevant Pages

  • Re: Input Mask on Date for Year or Month Only
    ... Can I use an input mask to caputre only the year or only the month? ... If you wish to use the DateTime functions, ... A DateTime datatype value must be a valid date, ... format, the stored value must contain the day as well. ...
    (microsoft.public.access.gettingstarted)
  • Re: Get and update only Time part from DateTime data type field
    ... If the column is of the datetime datatype, then the above statement is incorrect. ... doesn't have a format, the client application formats the value. ... "Kumar" wrote in message ...
    (microsoft.public.sqlserver.programming)
  • Re: Syntax error converting Date time string?
    ... All assumes that L.Date_Last_Used is a datetime datatype column. ... "safe" format and a character string is implicitly converted to ... > Roji - thanks for the fast repsone, ... P. Thomas" wrote in message ...
    (microsoft.public.sqlserver.programming)
  • Re: Searching on DATETIME Fields
    ... The datetime datatype does not store the ... > values in any readable format. ... The format you see is created by the ... >> Surely passing the value is all that is required regardless of the ...
    (microsoft.public.sqlserver.server)
  • Re: Inserting regional settings specific data into sql server
    ... All EU countries withouth the two English speaking use the format dd-MM-yy ... By using the parameters, while the program is in the right culture setting, ... than all those formats results using SQLparameters in the way the SQL server ...
    (microsoft.public.dotnet.framework.adonet)