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

SQL Statement / Query Woes...

Status
Not open for further replies.

aamaker

Programmer
Jan 20, 2002
222
US
Im trying to perform a search (data stored in MS Access DB) and the form Im using allows the following values:

- criteria1_minimum
- criteria1_maximum

those are stored in the database with datatype set to number.

Also on the form I have 8 specific regions (counties), setup as check boxes with unique names (i.e. field_county1, field_county2, etc.) -- so that the user can either search ALL the counties (i.e. all are checked) or filter by clearing some check boxes)

The first part, the comparing of the number values works when it exists alone, but when I try to add the portion of the sql select statement that handles the county selections it returns matches that DONT actuaally fall within the criteria specified in the search parameters.

Here is the sql select statement Im using:



Code:
... = "SELECT *  FROM Tbl_MyTbl  WHERE Acreage >= request.form("value1") And Acreage <= Request.form("value2") And MaxPrice <= Request.form("pricevalue") And County = '"&county1Val&"' Or County = '"&county2Val&"' Or County = '"&county3Val&"' Or County = '"&county4Val&"' Or County = '"&county5Val&"' Or County = '"&county6Val&"' Or County = '"&county7Val&"' Or County = '"&county8Val&"' "

What am I doing wrong or how can I get this to work? Im somewhat familiar with ASP, but as you can tell by now, far from a PRO.

(note: near the end of the sql select statement, the values county'x'Val are used to hold the request.form variable for the county check boxes)

Help?!?!
 
When mixing and [small]and[/small] or conditions, you usually need to use parenthesis.

Ex.

Where A=1 and b=2 and [!]([/!]County=1 or county=2 or county=3[!])[/!]



-George

Strong and bitter words indicate a weak cause. - Fortune cookie wisdom
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top