Wrox Programmer Forums
| Search | Today's Posts | Mark Forums Read
Classic ASP Databases Discuss using ASP 3 to work with data in databases, including ASP Database Setup issues from the old P2P forum on this specific subtopic. See also the book forum Beginning ASP.NET Databases for questions specific to that book. NOT for ASP.NET 1.0, 1.1, or 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Classic ASP Databases section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old January 24th, 2005, 12:05 PM
Friend of Wrox
 
Join Date: Jun 2003
Location: Oklahoma City, Oklahoma, USA.
Posts: 249
Thanks: 0
Thanked 0 Times in 0 Posts
Default problem with query

I'm hoping somebody can please help me with this query problem. I am wanting it to only search in only the states
where they have any of the particular criteria, such as in this example, it should only search Kentucky or Minnesota and
have displays and plastic bags. What is happening is that it is returning all the states with any of the criteria, it seems to
be ignoring the State IN statement.

strSQL = "SELECT Vendor_ID, CompanyName, FacilityName, Address, City, State, Zipcode " &_
            "FROM Table_02 WHERE " &_
            " SFOffsetPrinting_Less40 = 0 " &_
            " OR PrePress = 0 " &_
            " OR Displays = 1 " &_
            " OR PlasticBags = 1 " &_
            " OR SpecialityItems = 0 " &_
            " OR Forms = 0 " &_
            " OR Fulfillment = 0 " &_
            " AND State IN (" & strSearchStates & ");"


My response.Write statement:
SELECT Vendor_ID, CompanyName, FacilityName, Address, City, State, Zipcode FROM Table_02
WHERE SFOffsetPrinting_Less40 = 0 OR PrePress = 0 OR Displays = 1 OR
PlasticBags = 1 OR SpecialityItems = 0 OR Forms = 0 OR Fulfillment = 0
AND State IN ('Kentucky', 'Minnesota');

Thanks in Advance
Mike
__________________
Peace
Mike
http://www.eclecticpixel.com
 
Old January 24th, 2005, 12:36 PM
Friend of Wrox
 
Join Date: Jan 2004
Location: , , USA.
Posts: 303
Thanks: 0
Thanked 0 Times in 0 Posts
Default

When you use OR it mean any of the listed condition is true it will return result,

create a dynamic SQL WHERE clause based on the required criteria

something like this..

strSQL = "SELECT Vendor_ID, CompanyName, FacilityName, Address, City, State, Zipcode " &_
         "FROM Table_02 WHERE " &_
         "State IN (" & strSearchStates & ") "
IF (based on the input, if this need to be a criteria) THEN
    strSQL = strSQL & " AND SFOffsetPrinting_Less40 = 0 "
End IF
IF (based on the input, if this need to be a criteria) THEN
    strSQL = strSQL & " AND PrePress = 0 "
End IF
IF (based on the input, if this need to be a criteria) THEN
    trSQL = strSQL & " AND Displays = 1 "
End IF
IF (based on the input, if this need to be a criteria) THEN
    strSQL = strSQL & " AND PlasticBags = 1 "
End IF
IF (based on the input, if this need to be a criteria) THEN
    strSQL = strSQL & " AND SpecialityItems = 0 "
End IF
IF (based on the input, if this need to be a criteria) THEN
    strSQL = strSQL & " AND Forms = 0 "
End IF
IF (based on the input, if this need to be a criteria) THEN
    strSQL = strSQL & " AND Fulfillment = 0 "
End IF




Similar Threads
Thread Thread Starter Forum Replies Last Post
Query Problem. rupen Access 3 April 27th, 2007 07:43 AM
Query Problem bundersuk VB Databases Basics 0 December 30th, 2006 07:50 AM
query problem purnendu2311 Other Programming Languages 2 December 1st, 2006 02:53 PM
Problem in query leo_vinay Classic ASP Databases 5 January 21st, 2005 06:32 AM
query problem mateenmohd SQL Server 2000 7 September 9th, 2003 11:58 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.