| 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 datetimeDECLARE @EndDate datetimeSELECT [Date], IP, What, Query, Url, [Count]FROM dbo.FzoneLogsWHERE (What = 'Click') AND ([Date] BETWEEN StartDate AND EndDate)GOAm 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 datetimeDECLARE @EndDate datetimeSELECT @StartDate = 'SomeDateValue', @EndDate = 'SomeOtherDateValue'SELECT [Date], IP, What, Query, Url, [Count]FROM dbo.FzoneLogsWHERE (What = 'Click') AND ([Date] BETWEEN @StartDate AND @EndDate)GOTara Kizer |
 |
|
|
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 |
 |
|
|
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! |
 |
|
|
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 |
 |
|
|
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 |
 |
|
|
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! |
 |
|
|
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 |
 |
|
|
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 LarssonHelsingborg, Sweden |
 |
|
|
|