in reply to perl dates into string into SQL

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.

Replies are listed 'Best First'.
Re: Re: perl dates into string into SQL
by bean (Monk) on Sep 17, 2003 at 21:31 UTC
    hmerril has hit the nail on the head - you have a problem with converting your string representation of a date to the database representation of a date. MS Sql Server should (probably) automagically convert a datestring into a date if you present it in the expected format, whatever that is. I don't know MS Sql Server, but Oracle expects it as 'DD/MON/YYYY' (e.g. 17/SEP/2003). I haven't used ODBC in years, but I expect that hmerril is also correct in guessing it doesn't support the specific-to-MS-Sql-Server "cast" function. ODBC is database independent, so I bet the corresponding Oracle function "to_date" isn't supported either.