August 17, 2015 at 3:47 am
Hi All,
I was doing so well with SSRS but this time dates going to break me.
I have table with dates in following format 2015-01-01 23:58:00.000 and my SQL SELECT query has following clause
WHERE (CONVERT(VARCHAR(10), cast( arrivaldate as datetime), 103)) between @StartDate and @EndDate
I can execute it in SSRS query designer with manually entering date parameters in "define query parametrs" e.g. 01/01/2015 it works fine but when I run report ....The conversion of a varchar data type to a datetime data type resulted in an out-of-range value.
any advise appreciated.
August 17, 2015 at 4:50 am
Please will you post your whole query and a CREATE TABLE statement for the table you're selecting from?
Thanks
John
August 17, 2015 at 6:08 am
don't convert dates to strings! the where statement you posted ends up causing a table scan, as it converts every date to a string, which in turn gets compared to a date.
dates should be dates, and stay dates.
WHERE (CONVERT(VARCHAR(10), cast( arrivaldate as datetime), 103)) between @StartDate and @EndDate
assuming StartDate and EndDate are datetime parameters, you can simply do this:
WHERE arrivaldate between @StartDate and @EndDate
if arrival date is not a datetime(which is implied by the double conversion)
you might need a case statement or an extra comparison in the WHERE clause
WHERE ISDATE(arrivaldate ) = 1 AND CONVERT(datetime,arrivaldate) between @StartDate and @EndDate
Lowell
August 17, 2015 at 7:28 am
thanks for reply guys. total fail on my side ...not sure why I got in to my head that I need to convert this to dd/mm/yyyy format before comparing it to parameter . again thx for pointers
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply