Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SQL Problem with selecting dates

Status
Not open for further replies.

AllMememe

Technical User
Feb 3, 2011
5
I have a table called Match which has columns DateFrom and DateTo. I need my query to get all records that have their DateFrom OR DateTo between two selected dates.

I tried:

Select distinct P.FName, M.Team from Match M Person P where P.Team = M.Team and M.DateFrom OR M.DateTo between #02/Feb/2011# and #09/Feb/2011#

This however returns all the wrong records.

Any help would be appreciated. Thanks.
 

You missed a COMMA in the FROM andBETWEEn for BOTH dates...
Code:
Select distinct
  P.FName
, M.Team 
from
  Match M
, Person P 
where P.Team = M.Team
  and (M.DateFrom between #02/Feb/2011# and #09/Feb/2011#
   OR  M.DateTo between #02/Feb/2011# and #09/Feb/2011#)


Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 


please note that the PARENTHESES are very important to the logic that you stated.

Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top