[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 274
  • Last Modified:

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
0
MikeHall12
Asked:
MikeHall12
5 Solutions
 
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
[Webinar] Improve your customer journey

A positive customer journey is important in attracting and retaining business. To improve this experience, you can use Google Maps APIs to increase checkout conversions, boost user engagement, and optimize order fulfillment. Learn how in this webinar presented by Dito.

 
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
 
MikeHall12Author Commented:
I found the problem by myself. CreateDate is updated in Database, so that is the reason it is not displaying values.
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now