Wrox Programmer Forums

Need to download code?

View our list of code downloads.

| FAQ | Members List | Calendar | 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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
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
Reply With Quote
  #2 (permalink)  
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
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 03:16 AM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.