I am retrieving a bunch of values out of one database, trying to fix the format and reinsert into a different master database, which would usually be fine, but 3 of my values are giving me a heck of a time. There are three numeric values in the first DB that I would like to format into a date time and insert into the new DB

#Taking the values one at a time, and assigning to variables $DOBYear = $ayDOB_Year[$i]; $DOBMonth = $ayDOB_Month[$i]; $DOBDay = $ayDOB_Day[$i]; #Concatonating the string $ODBCDate = sprintf("%4d-%02d-%02d", $DOBYear, $DOBMonth, $DOBDay);

Up to hear everything is groovy, but when I try to insert this into the new SQL table I am getting the following error:

Error:
[242] [2] [0]
"[Microsoft][ODBC SQL Server Driver][SQL Server]
The conversion of a char data type to a datetime data type resulted in an out-of-range date time value."

Ok so then I tried casting it on the insert statement, and it still isn't working!

$sqlInsert = "Insert into tblMaster (List_Name_, Gender_, First_Name_, + Last_Name_, Full_Name_, Address_1_, City_, State_, Zip_Code_, SCF_Co +de_, Country_, Email_, Domain_Name_, TLD_, DOB_) Values ('$ListName', +'$Gender','$FirstName','$LastName','$FullName','$Address','$City','$S +tate','$Postal','$SCF','$Country', '$Email','$DomainName','$TLD', cas +t('$ODBCDate' as datetime))";

When I print the SQL statement out to the window and paste into SQL it works fine!! Anyone have any insight??

janitored by ybiC: <code> tags around example code, <tt> around error message


In reply to perl dates into string into SQL by jenalice

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.