Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Dynamic Date Range...

Author  Topic 

jacobh
Starting Member

3 Posts

Posted - 2006-07-17 : 14:22:30
Hello,

I am attempting to use a date range (something similar that I had working in Access using a few parameters). Here is my code and it is returning zero results. The date time fields are separate...

DECLARE @StartDate datetime
DECLARE @EndDate datetime

SELECT [Date], IP, What, Query, Url, [Count]
FROM dbo.FzoneLogs
WHERE (What = 'Click') AND ([Date] BETWEEN StartDate AND EndDate)
GO

Am I missing something???

Thanks!

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2006-07-17 : 14:25:00
You've defined two variables but you haven't set them to anything, plus you aren't using the variables in your query.

DECLARE @StartDate datetime
DECLARE @EndDate datetime

SELECT @StartDate = 'SomeDateValue', @EndDate = 'SomeOtherDateValue'

SELECT [Date], IP, What, Query, Url, [Count]
FROM dbo.FzoneLogs
WHERE (What = 'Click') AND ([Date] BETWEEN @StartDate AND @EndDate)
GO

Tara Kizer
Go to Top of Page

humanpuck
Yak Posting Veteran

94 Posts

Posted - 2006-07-17 : 14:38:22
Try getting rid of the between.

where What like 'Click' and
[date] >= @startdate and
[date] <= @enddate
Go to Top of Page

jacobh
Starting Member

3 Posts

Posted - 2006-07-17 : 14:39:16
Thanks for the replies...

Is there a way to make them dynamic as the dates will probably never be the same dates...a way to make the user enter a value??

Thanks!
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2006-07-17 : 14:57:15
quote:
Originally posted by humanpuck


where What like 'Click' and



What's the purpose of that part?

quote:
Originally posted by humanpuck

[date] >= @startdate and
[date] <= @enddate



That's the same thing as BETWEEN.

Tara Kizer
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2006-07-17 : 14:57:38
quote:
Originally posted by jacobh

Thanks for the replies...

Is there a way to make them dynamic as the dates will probably never be the same dates...a way to make the user enter a value??

Thanks!



Yes. You would do this in your application though.

Tara Kizer
Go to Top of Page

jacobh
Starting Member

3 Posts

Posted - 2006-07-17 : 15:12:40
Ah OK. I was hoping SQL would be able to manipulate the data itself...would an Access adp report be able to ask for a date range? When the db was in Access, I set the parameters in the query but it seems that I cannot modify a SQL procedure when viewing from the adp...is there a way to display the start and end date prompts through a report?

Thanks!
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2006-07-17 : 15:22:33
I don't know anything about Access. You might want to post your question in the Access forum here.

Tara Kizer
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2006-07-17 : 16:05:50
Can't do that in SQL Server. In Access, whenever an unknown parameter is found, Access shows a dialog box and asks the user to input a value.


Peter Larsson
Helsingborg, Sweden
Go to Top of Page
   

- Advertisement -