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 Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

easy criteria question

Status
Not open for further replies.

Ferntown

Technical User
Jan 15, 2004
11
CA
I need to run a query that will select only the records between 1990 and 1999. Currently, this query selects the records that are >=1990, how do I add in <=1999.

SQL:
SELECT Streets.[St_ID#], Streets.StName, Streets.StName2, Streets.Year, Streets.StType, Streets.StWidth, Streets.StWidth_Future, Streets.StLength, Streets.StEdgeA, Streets.StEdgeB, Streets.StDensity, Streets.StClass, Streets.[N_ID#], Streets.StSurfaceType,
FROM Streets
WHERE (((Streets.Year)>=1990)) OR (((Streets.StEdgeA)="B") AND ((Streets.StEdgeB)="B") AND ((Streets.[N_ID#])=1) AND ((Streets.StSurfaceType)="Asphalt"));

Thanks
 
Change This
[tt]
WHERE Streets.Year >=1990
[/tt]

to this
[tt]
WHERE Streets.Year BETWEEN 1990 AND 1999
[/tt]
 
Thanks for the help. I tried the BETWEEN command but for some reason the query is bringing in null records and a bunch of records from 1983, 1975, etc etc.
I can't fiqure that out.
Mitch
 
Its probably because your WHERE clause is using OR conditions. This
[tt]
WHERE Streets.Year) BETWEEN 1990 AND 1999
OR Streets.StEdgeA ="B" AND Streets.StEdgeB ="B"
AND Streets.[N_ID#] =1 AND Streets.StSurfaceType ="Asphalt"
[/tt]

will bring in records that fit the Year range OR Records that satisfy the remaining clauses.

You probably want something like
[tt]
WHERE (Streets.Year BETWEEN 1990 AND 1999 )
AND (Streets.StEdgeA ="B" AND Streets.StEdgeB ="B"
AND Streets.[N_ID#] =1 AND Streets.StSurfaceType ="Asphalt")
[/tt]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top