Hi, I am trying to cast or convert the datevalue (from varchar) to date type and compare the date and get the records of last 3 days onwards and ignore previous records. The current date format is 'yyyymmdd'.
I used the following statements and compare value to -3 days to current date. So want the dates which are above -3 days to current date, so I used the following:
(cast ('yyyymmdd' as datetime) >= dateadd(day, -3, getdate()))
or
(convert(datetime, 'yyyymmdd', 120) >= dateadd(day, -3, getdate()))
I have tested this in query analyser and works perfect. So I used the same in a procedure and executed the procedure from jdbc-odbc but the ResultSet is still getting the dates before -3 days like last month, last year dates records also generated. So I need this to be resoved ASAP.
Could anyone give me a solution quickly. Very urgent. Thanks in advance.
I used the following statements and compare value to -3 days to current date. So want the dates which are above -3 days to current date, so I used the following:
(cast ('yyyymmdd' as datetime) >= dateadd(day, -3, getdate()))
or
(convert(datetime, 'yyyymmdd', 120) >= dateadd(day, -3, getdate()))
I have tested this in query analyser and works perfect. So I used the same in a procedure and executed the procedure from jdbc-odbc but the ResultSet is still getting the dates before -3 days like last month, last year dates records also generated. So I need this to be resoved ASAP.
Could anyone give me a solution quickly. Very urgent. Thanks in advance.

SQL Date
Phenom
Two thoughts come to mind -
1. We've used convert(varchar,getdate()-3,101) to generate a date for three days ago. This statement strips off the time and leaves you with a date with a time of midnight.
2. If you changed your stored procedure, did you rerun the create procedure statement to place the code into use If you don't recreate the stored procedure, you're still using the old code.
EricSS
sounds strange.DId you try to use perhaps datediff to see if that brings back the same results
WHERE DATEDIFF(day,YourColumns,GETDATE()) <= 3
HTH, Jens Suessmeyer.
---
http://www.sqlserver2005.de
---