Wrox Programmer Forums
|
Classic ASP Basics For beginner programmers starting with "classic" ASP 3, pre-".NET." 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 Basics 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 May 10th, 2006, 03:18 AM
Friend of Wrox
 
Join Date: May 2005
Posts: 149
Thanks: 0
Thanked 0 Times in 0 Posts
Default search query problem

Hey
I have the following query to search 3 fields Category,title,details
I do not know hot to use and or together.
The search form has a box for details and a listbox for category
I want that when it searches the db it the category be exactly like what the user chooses from the list BUT it searches both the title or description for details the user enters.
this query works but if for ex the category is the same but the title or details does not exist it will produce no result
I think the problem is with these 2 and or
if I use both operators with "and" then all the input should be right

Rs.Open "SELECT * FROM products where Category like " & "'%" & strKeyword & "%'" &_
    " and title like " & "'%" & strKeyword & "%'" &_
    " or details like " & "'%" & strKeyword & "%'" &_
    " order by " & strOrder & " " & strSort, Conn,3, 3


 
Old May 11th, 2006, 09:52 AM
Friend of Wrox
 
Join Date: May 2006
Posts: 643
Thanks: 0
Thanked 0 Times in 0 Posts
Default

It is unclear to me the exact result you desire.

My best guess is as follows:
Select records where the category is a match, and either the title OR the details match. (By match, in the context of your select statement, I mean "Like"... since you are using "Like", which means that a match occurs when the field contains the value between the percent signs anywhere within it).

If this is your quest, then you must parenthesize thusly:
Select records where the catergory is a match and (either the title or the details match)

So changing your code will produce this result (assuming there are no typos, etc):

"SELECT * FROM products where Category like " & "'%" & strKeyword & "%'" &_
    " and (title like " & "'%" & strKeyword & "%'" &_
    " or details like " & "'%" & strKeyword & "%')" &_
    " order by " & strOrder & " " & strSort

I hope that helps. Please let me know if I misunderstood your question




Woody Z http://www.learntoprogramnow.com
 
Old May 11th, 2006, 10:56 AM
Friend of Wrox
 
Join Date: May 2005
Posts: 149
Thanks: 0
Thanked 0 Times in 0 Posts
Default

That is exactly what I mean.Sorry for confusion because english is not my lang.
thanks a lot woodyz

 
Old May 11th, 2006, 11:01 AM
Friend of Wrox
 
Join Date: May 2006
Posts: 643
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Ahh... don't worry about the confusion - it is usually my fault when I don't understand something.

You're welcome - I hope that solved your problem...

Woody Z http://www.learntoprogramnow.com





Similar Threads
Thread Thread Starter Forum Replies Last Post
Query to Search for a value in a table Vendirella SQL Language 0 October 10th, 2007 12:47 AM
query name search dstein4d Access VBA 1 August 13th, 2007 12:19 PM
search problem bburcan VS.NET 2002/2003 0 October 30th, 2006 10:39 AM
Trimming a query for search arnabghosh Classic ASP Databases 1 May 31st, 2005 07:39 AM
Users selection driven search query... mat41 Classic ASP Databases 3 November 16th, 2004 03:14 AM





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