Hi monks,
Sorry to say , I don't whether it is sql question or perl question, anywhere I just post it..
I am using win32:odbc to run sql job, it's success when I insert record and show all record :
sample output
2659 Unix iserver10 2008-05-01 03:35:00 /var 0.5 0.43 14.0
Record 2660
2660 Unix iserver10 2008-05-01 03:35:00 /zLab 1.19 0.8 33.0
Record 2661
2661 Unix iserver10 2008-05-01 03:40:00 / 0.91 0.32 65.0
Record 2662
2662 Unix iserver10 2008-05-01 03:40:00 /backupd 2.94 1.83 38.0
Record 2663
2663 Unix iserver10 2008-05-01 03:40:00 /fr_dev1 1.97 0.74 63.0
Record 2664
2664 Unix iserver10 2008-05-01 03:40:00 /fr_dev1 2.5 0.43 83.0
the record is insert by perl script and the field of "DateTime" is combined like the above "2008-05-01 03:40:00" which field is format as "yyyy-mm-dd hh:mm:ss"
I try to run the following sql but obtain error,
even I can run the command within ms access sql command, I try to copy and paste to perl script and run it
obtain
Error in SQL query: "select Date_time from Main where Date_Time >= Dat
+eAdd("h",
-2, '12/05/2008 03:35') "!
Error: [-3010] [1] [0] "[Microsoft][ODBC Microsoft Access Driver] Too
+few parame
ters. Expected 1."
$sql = "select Date_time from Main where Date_Time >= DateAdd(\"h\", -
+2, '1/05/2008 05:35') ";
The full code;
# Display a table in a database using PERL ODBC module
use Win32::ODBC;
$dsn = "testDB";
$table = "Main";
# ====== Check if the database can be opened correctly
if (!($db = new Win32::ODBC($dsn))) {
print "Error in opening DSN \"$dsn\"!\n";
print "Error: " . Win32::ODBC::Error(). "\n";
exit;
}
# ====== Select all fields from the given table
$sql = "select Date_time from Main where Date_Time >= DateAdd(\"h\", -
+2, '1/05/2008 05:35') ";
# ====== Check if the SQL query is correct
if ($db->Sql($sql)) {
print "Error in SQL query: \"$sql\"!\n";
print "Error: " . $db->Error() . "\n";
$db->Close();
exit;
}
# ====== Print field data
print "Content-type: text/html\n\n";
print "<html><body><pre>\n";
$count = 1;
@FieldNames = $db->FieldNames();
while ($db->FetchRow()) {
print "Record $count\n";
%Data = $db->DataHash();
foreach $x (@FieldNames) {
#print "$x: $Data{$x}\n";
print "$Data{$x} ";
}
print "\n";
$count++;
}
$db->Close();
Is it the problem about the date format ? is there any method force the string to date format ? or I need to use other module ?
Thanks a lot