Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Basic datetime comparison

Author  Topic 

alberto_alvarado
Starting Member

3 Posts

Posted - 2007-09-25 : 04:12:55
Hi, I´m new to SQL Server, and I´m having the following problem. I have this query:

SELECT
P.DIMENSION, P.CUSTACCOUNT, C.NAME AS CUSTOMERNAME, PE.PROJID, P.NAME AS PROJNAME, PE.EMPLID, E.NAME AS EMPLNAME,
PE.FECHAASIGNACION, PE.FECHADESASIGNACION
FROM
PROJVALEMPLPROJSETUP PE, EMPLTABLE E, PROJTABLE P, CUSTTABLE C
WHERE
PE.PROJID = P.PROJID AND PE.EMPLID = E.EMPLID AND P.CUSTACCOUNT = C.ACCOUNTNUM AND ((PE.FECHAASIGNACION >= '01/01/2006' AND PE.FECHAASIGNACION < '19/09/07')
AND PE.FECHADESASIGNACION >= '01/01/2007')
ORDER BY
P.DIMENSION, P.CUSTACCOUNT, PE.PROJID, PE.EMPLID


When I execute it, I get this error, regarding the date comparison I´m trying:

The conversion of a char data type to a datetime data type resulted in an out-of-range datetime value.

How do I compare a string value to a datetime from the database? Thanks a lot.

harsh_athalye
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2007-09-25 : 04:17:32
[code]Select
....
... AND ((PE.FECHAASIGNACION >= '20060101' AND PE.FECHAASIGNACION < '20070719')
AND PE.FECHADESASIGNACION >= '20070101')[/code]

Use ISO yyyymmdd format while doing date comparison.

Harsh Athalye
India.
"The IMPOSSIBLE is often UNTRIED"
Go to Top of Page

alberto_alvarado
Starting Member

3 Posts

Posted - 2007-09-25 : 04:26:23
Thank you very much. That did it.
Go to Top of Page
   

- Advertisement -