Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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.

Posted on 2004-10-26
8
Medium Priority
?
269 Views
Last Modified: 2006-11-17
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
Comment
Question by:MikeHall12
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
8 Comments
 
LVL 6

Assisted Solution

by:Duane Lawrence
Duane Lawrence earned 400 total points
ID: 12415650
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
 
LVL 70

Assisted Solution

by:Scott Pletcher
Scott Pletcher earned 400 total points
ID: 12415674
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
 

Author Comment

by:MikeHall12
ID: 12415737
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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

Author Comment

by:MikeHall12
ID: 12415793
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
 
LVL 32

Assisted Solution

by:Brendt Hess
Brendt Hess earned 1200 total points
ID: 12415993
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
 
LVL 32

Assisted Solution

by:Brendt Hess
Brendt Hess earned 1200 total points
ID: 12416006
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
 
LVL 32

Accepted Solution

by:
Brendt Hess earned 1200 total points
ID: 12416040
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
 

Author Comment

by:MikeHall12
ID: 12416124
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 learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
Ready to get certified? Check out some courses that help you prepare for third-party exams.
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.
Via a live example, show how to shrink a transaction log file down to a reasonable size.

636 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question