Get rows between 2 dates

This is SQL 2000...

I have some rows with datetime stamp. I wrote a stored proc, pass start date and end date to it and i need to get the rows in between...

I tried the 2 below and I dont get anything. If I do "@enddate + 1", then i get all the rows....

The dates i have are like this:
2011-04-06 09:01:30.237
2011-04-06 09:02:01.237
2011-04-06 10:00:03.330
2011-04-06 11:00:03.550
from table

where --updatedate > = DATEADD(dd, 0, DATEDIFF(dd, 0, @startDate)) 
      --and 
     --updatedate < DATEADD(dd, 0, DATEDIFF(dd, 0, @endDate + 1 )) 
      updatedate  between DATEADD(dd, 0, DATEDIFF(dd, 0, @startDate))  and DATEADD(dd, 0, DATEDIFF(dd, 0, @endDate ))

Open in new window

LVL 8
CamilliaAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

LordWabbitCommented:
You need to ensure that your time on the time is from 00:00 on your start date to 23:59 on your enddate.
0
Patrick MatthewsCommented:
Never use between when testing for datetimes.

where updatedate >= DATEADD(dd, DATEDIFF(dd, 0, @startDate), 0)  and
    updatedate < DATEADD(dd, DATEDIFF(dd, 0, @endDate) + 1, 0)


LordWabbit:

>>You need to ensure that your time on the time is from 00:00 on your start date to 23:59 on your enddate

Nope.  That still leaves the possibility of 23:59:01.
0
BardobraveCommented:
If you don't pass times in your procedure parameters your system will assume they are at 0:00:00, wich can let out of your queries a lot of valid results on EndDate day.
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

CamilliaAuthor Commented:
so, what should I do??
0
CamilliaAuthor Commented:
I have dates like this:
2011-04-06 09:01:30.237
2011-04-06 09:02:01.237
2011-04-06 10:00:03.330
2011-04-06 11:00:03.550
2011-04-06 11:06:48.497
2011-04-06 11:08:25.590
2011-04-06 11:11:58.060

I pass '2011-04-06 09:00:00.000','2011-04-06 10:02:01.237'

but get all rows
0
Patrick MatthewsCommented:
Farzadw,

Well, what results do you want?  If you pass '2011-04-06 09:00:00.000','2011-04-06 10:02:01.237', would you expect to get only:

2011-04-06 09:01:30.237
2011-04-06 09:02:01.237
2011-04-06 10:00:03.330

If so:

WHERE updatedate >= @startDate And updateDate <= @endDate

If you would want all of those rows returned, use the syntax from my last comment.

Patrick
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.