troubleshooting Question

Date range queries in SQL 2005 Reporting Services.

Avatar of CSTX_Analysts
CSTX_AnalystsFlag for United States of America asked on
Microsoft SQL ServerDB Reporting ToolsMicrosoft SQL Server 2005
5 Comments1 Solution714 ViewsLast Modified:
Below are listed two code snippets from a recent project I have been working on. What I am trying to do is compare two dates and return all of the results that fall on or between the two dates. The first code snippet will return the starting date that I input and every day up to, but NOT including, the end date I input.

The second snippet returns all of the data I want INCLUDING data from the end date I input. I have tried using  <=. This will not error out but it still returns incorrect data in the same way the first code snippet does.

My question is , is this by design? In  other words is the second code snippet the correct way to compare dates or am I missing something that could make this process easier.

Any help is appreciated.
(Code that does not work)
SELECT *
  FROM  table
where (modifieddate >@begindate and modifieddate<@enddate)



(Code that does work)
SELECT *
  FROM  table
where  (modifieddate >@begindate and dateadd(day,-1,modifieddate) <@enddate)









Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 5 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 5 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros