DATE query
-
I have a field called occdate which I need to query. This code works fine and retreives the record
SELECT OccID FROM dbo.People_Occ WHERE (OccDate >= 01 / 08 / 2006)
However when i add a second parameter i get no results returnedSELECT OccID FROM dbo.People_Occ WHERE (OccDate >= 01 / 08 / 2006) AND (OccDate < 01 / 08 / 2007)
Can anyone tell me why? -
I have a field called occdate which I need to query. This code works fine and retreives the record
SELECT OccID FROM dbo.People_Occ WHERE (OccDate >= 01 / 08 / 2006)
However when i add a second parameter i get no results returnedSELECT OccID FROM dbo.People_Occ WHERE (OccDate >= 01 / 08 / 2006) AND (OccDate < 01 / 08 / 2007)
Can anyone tell me why?The where clause will be something along the lines of: WHERE OccDate BETWEEN StartDate AND EndDate But it is impossible to give you the exact syntax without knowing what database you are using.
-
The where clause will be something along the lines of: WHERE OccDate BETWEEN StartDate AND EndDate But it is impossible to give you the exact syntax without knowing what database you are using.
Keith Malwitz wrote:
The where clause will be something along the lines of
Not necessarily. It is perfectly valid to say a is greater than x and a is less than y as the OP did. In fact, it gives more clarity because the BETWEEN clause doesn't intrinsically tell you if it is inclusive or exclusive of the values used. In the OP's case he's using a mix. The start date is inclusive and the end date is exclusive, so the BETWEEN clause is just not going to work for him. -- modified at 18:57 Sunday 27th August, 2006
Upcoming Scottish Developers events: * UK Security Evangelists On Tour (2nd November, Edinburgh) * Developer Day Scotland: are you interested in speaking or attending? My: Website | Blog
-
I have a field called occdate which I need to query. This code works fine and retreives the record
SELECT OccID FROM dbo.People_Occ WHERE (OccDate >= 01 / 08 / 2006)
However when i add a second parameter i get no results returnedSELECT OccID FROM dbo.People_Occ WHERE (OccDate >= 01 / 08 / 2006) AND (OccDate < 01 / 08 / 2007)
Can anyone tell me why?Without knowing which database you are using this is difficult to answer. I always put the date in ISO format (i.e. yyyy-mm-dd) to ensure that the parser doesn't swap the month and date around depending on the locale. Also, I typically use parameters:
SELECT OccID
FROM dbo.People_Occ
WHERE (OccDate >= @minDate) AND (OccDate < @maxDate)
Upcoming Scottish Developers events: * UK Security Evangelists On Tour (2nd November, Edinburgh) * Developer Day Scotland: are you interested in speaking or attending? My: Website | Blog
-
I have a field called occdate which I need to query. This code works fine and retreives the record
SELECT OccID FROM dbo.People_Occ WHERE (OccDate >= 01 / 08 / 2006)
However when i add a second parameter i get no results returnedSELECT OccID FROM dbo.People_Occ WHERE (OccDate >= 01 / 08 / 2006) AND (OccDate < 01 / 08 / 2007)
Can anyone tell me why?Try this:
SELECT OccID
FROM dbo.People_Occ
WHERE (OccDate >= '01/08/2006') AND (OccDate < '01/08/2007')--EricDV Sig--------- Some problems are so complex that you have to be highly intelligent and well informed just to be undecided about them. - Laurence J. Peters
-
Try this:
SELECT OccID
FROM dbo.People_Occ
WHERE (OccDate >= '01/08/2006') AND (OccDate < '01/08/2007')--EricDV Sig--------- Some problems are so complex that you have to be highly intelligent and well informed just to be undecided about them. - Laurence J. Peters