Date Range Bug: If I give param as 08/01/2004 and 08/30/2004 no results but If I give param as 10/01/2004 and 10/30/2004 the results are displaying with this query.

I have a query below, for that IF I provide parameters as 08/01/2004 and 08/30/2004 no results but If I give parameters as 10/01/2004 and 10/30/2004 the results are displaying with this query.
May be I am doing something wrong in DARTEADD FUNCTION. Can you help me resolve this problem in this below query

CREATE  PROCEDURE usp_test

@BeginDate DateTime,
@EndDate DateTime

AS

SELECT P.DocID, count(pageID) as Pages
FROM tb_Page P
INNER JOIN tb_Doc D on P.DocID = D.DocID
WHERE P.CreateDate >= @BeginDate
AND P.CreateDate < dateadd(day, 1, @EndDate)
AND D.Status > 0
GROUP BY P.DocID
HAVING COUNT(PageID) > 6
GO

Thanks
Mike
MikeHall12Asked:
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.

Duane LawrenceCommented:
Your asking for opposites:

WHERE P.CreateDate >= @BeginDate
AND P.CreateDate < dateadd(day, 1, @EndDate)

Note the >= and < are on the same variables, this will exclude everything.

Duane
0
Scott PletcherSenior DBACommented:
Is the column CreateDate a DATETIME datatype?

Are you *sure* there are records matching August in the tables?  Maybe it's not returning records because there really aren't any matching ones :-) .  What result does this give?:

SELECT COUNT(*)
FROM tb_Page
WHERE CreateDate >= '08/01/2004' AND CreateDate < DATEADD(DAY, 1, '08/30/2004')


Btw, did you want 08/31/2004 or 08/30/2004?
0
MikeHall12Author Commented:
Scott,
With the below query that you mentioned does return 0 output
SELECT COUNT(*)
FROM tb_Page
WHERE CreateDate >= '08/01/2004' AND CreateDate < DATEADD(DAY, 1, '08/30/2004')

but there are records in DB with '08/01/2004'  and '08/30/2004'
If I put the parameters 07/20/2004 to 10/30/2004, I am getting records .

Thanks for the reply
Mike
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.

MikeHall12Author Commented:
duane,
you are saying that the variable is same that will exclude everything.
but How come I am returning records with this parameters 10/01/2004 and 10/30/2004.
Please help me resolve.
Mike
0
Brendt HessSenior DBACommented:
Do me a favor.  Execute the following, and show the output as shown in Query Analyzer:

SELECT
 Top 10  'Type1' as Typ, CreateDate
 FROM (Select CreateDate FROM tbl_Page
 WHERE CreateDate >= '20040801' Order By CreateDate) Type1
UNION
 Top 10  'Type2' as Typ, CreateDate
 FROM (Select CreateDate FROM tbl_Page
 WHERE CreateDate >= '08/01/2004' Order By CreateDate) Type2
0
Brendt HessSenior DBACommented:
Better yet - show the results of this query:
SELECT CreateDate, Count(*)
FROM tbl_Page
WHERE CreateDate >= '08/01/2004'
Group By CreateDate
Order By CreateDate
0
Brendt HessSenior DBACommented:
DUH!  I hate doing that.

The problem seems to be that there is not 6+ pages in the given range.  And, since I did not filter off the times, those queries will not actually produce any good results.  Try:

SELECT P.DocID, Count(PageID) As Pages, Month(CreateDate) As Mth
FROM tbl_Page P
INNER JOIN tb_Doc D
    on P.DocID = D.DocID
WHERE P.CreateDate >= '08/01/2004'
AND D.Status > 0
Group By Month(CreateDate), p.Docid
Order By Month(CreateDate), Count(PageID) Desc
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
MikeHall12Author Commented:
I found the problem by myself. CreateDate is updated in Database, so that is the reason it is not displaying values.
0
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.