Monday, February 20, 2012

Problem With Datatime

Hi everybody.
I am new in SQL SERVER and I have a problem with a datetime

I have a select. It works in a database but
it doesnt work in other database.

The error is the next :

2004-04-20 13:37:32,781 INFO [STDOUT] ConexionBDExceptionjava.sql.SQLException: [Microsoft][SQLServer JDBC Driver][SQLServer]The conversion of a char data type to a datetime data type resulted in an out-of-range datetime value

The select is:

SELECT id_solicitud from solicitudes where
fecha_apertura >= '01/03/04'
AND fecha_apertura <= '31/03/04 23:59:59.999'
ORDER BY fecha_apertura DESC

Thanks for attention.
PILARMy moneys on a different collation...|||It looks like you are feeding the date into the select in dd/mm/yy and not mm/dd/yy. The 3/1 could be Jan 3 or Mar 1, but there will never be a 3rd day of the 31st month.

Try this:

SELECT id_solicitud from solicitudes where
fecha_apertura >= '01/03/04'
AND fecha_apertura <= convert(datetime,'31/03/04 23:59:59.999', 131)
ORDER BY fecha_apertura DESC

Tom

No comments:

Post a Comment