Unless I'm missing something, you don't tell which database you are using ODBC to access - which database is it?
The book "Programming the Perl DBI" p. 293 describes DBD::ODBC date handling:
You can use ODBC escape sequences to define a date in a
database independent way. For example, to insert a date
of Jan 21, 1998 into a table, you could use:
INSERT INTO table_name (date_field) VALUES ({d '1998-01-21'});
Similar escape sequences are defined for other date/time
types. Here's the full set:
{d 'YYYY-MM-DD'} - date
{t 'HH:MM:SS'} - time
{ts 'YYYY-MM-DD HH:MM:SS'} - timestamp
{ts 'YYYY-MM-DD HH:MM:SS.FFFFFF'} - timestamp
and there's more, but you get the gist.
Maybe the 'cast' is a MS SQL Server function that DBD::ODBC doesn't support - just a guess. That would explain why you can cut and paste the insert into an SQL Server client session and it works, but it doesn't work in DBI with DBD::ODBC.
I'm not familiar with DBD::ODBC, but if I were you I'd check the DBD::ODBC perldocs to see if interaction with 'dates' is described in there. Do
perldoc DBD::ODBC
at a command prompt to read the documentation that comes with the DBD::ODBC module.
Hope this helps.
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.