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


In reply to question for SQL date with win32:odbc by benlaw

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.