473,659 Members | 2,980 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

SQL exact search

347 Contributor
I have the following code that works very well, the problem is that of i search for say rap it returns back results that contain the words telegraph, grapfruit etc, how can i get it to just return results that have the word rap in the search string anywhere??

Expand|Select|Wrap|Line Numbers
  1. <%
  2. Dim strSearch, myarray, strSQL, strSQLExtra 
  3. If Not Request.Form("search") = "" Then 
  4. session("search") = Request.Form("search") 
  5. session("choice") = Request.Form("choice") 
  6. session("queryterm") = session("queryterm")+" "+Request.Form("search")
  7. End If 
  8.  
  9. 'Loop is now in a function, so that we can feed it each field name. 
  10. Function addparams(fieldname,wordArray)  
  11. Dim tmp 
  12. tmp = "" 
  13.     For each item in wordArray 
  14.     tmp = tmp & " (" & fieldname & " Like '%" & item & "%') " & session("choice") & " " 
  15.     next 
  16.     tmp = left(tmp, len(tmp)-4) ' Chops off the last "AND " 
  17.     addparams = tmp 
  18. End Function 
  19.  
  20. 'Build the word array 
  21. myarray = split(session("search"), " ") 
  22.  
  23. 'Build the SQL  
  24. strSQL = "SELECT * FROM mp3 INNER JOIN celebs ON mp3.celebid = celebs.idnumber WHERE (" 
  25.  
  26. strSQL = strSQL & addparams("filename", myarray) ' change field one! 
  27.  
  28. strSQL = strSQL & ") OR (" 
  29.  
  30. strSQL = strSQL & addparams("mp3type", myarray) ' change field two! 
  31.  
  32. strSQL = strSQL & ")order by surname, firstname, filename;" 
  33. session("sqlset") = strSQL
  34.  
  35.   %>
Oct 15 '09 #1
4 2646
CroCrew
564 Recognized Expert Contributor
Hello colinod,

Here is an example that does what your looking to do.

Expand|Select|Wrap|Line Numbers
  1. <%
  2.     Function WordFinder(FullString, WordToFind)   
  3.         myarray = split(FullString)
  4.         For each item in myarray  
  5.             If (item = WordToFind) Then
  6.                 WordFinder = "Found!"
  7.                 Exit Function
  8.             End If
  9.         next  
  10.         WordFinder = "Not Found."
  11.     End Function  
  12. %>
  13. <html>
  14.     <head>
  15.         <title>Test Page</title>
  16.     </head>
  17.     <body>
  18.         <%
  19.             If (Request.ServerVariables("REQUEST_METHOD") = "POST") Then
  20.                 Response.Write("Looking for [" & Request.Form("xFind") & "]<br />")
  21.                 Response.Write("In [" & Request.Form("xString") & "]<br />")
  22.                 Response.Write(WordFinder(Request.Form("xString"), Request.Form("xFind")))
  23.             End If
  24.         %>
  25.  
  26.         <form method="POST" name="xForm" action="Index.asp">
  27.             String: <input type="text" name="xString"><br />
  28.             Find this: <input type="text" name="xFind"><br />
  29.             <input type="Submit" name="xSubmit" value="Find">
  30.         </form>
  31.     </body>
  32. </html>
  33.  
Hope it helps,
CroCrew~
Oct 15 '09 #2
CroCrew
564 Recognized Expert Contributor
in the first box type in "Hello how are you today Michelle" and the second box type in "to". There should be no matches.

then for the second test:

in the first box type in "Hello how are you today Michelle" and the second box type in "today". There should be a match now.

Hope that that helped you out,
CroCrew~
Oct 15 '09 #3
colinod
347 Contributor
Hi thanks for that but i am trying to do this with sql in an asp page, am i in the wrong place for this question?
Oct 15 '09 #4
CroCrew
564 Recognized Expert Contributor
Hello Colinod,

I think you'd have to search for '% rap %' and include the spaces in the search. Like this:

Expand|Select|Wrap|Line Numbers
  1. SELECT * FROM [table] WHERE (([field] LIKE '% rap %') OR ([field] LIKE '% rap%') OR ([field] LIKE '%rap %'))
  2.  
Hope that helps,
CroCrew~
Oct 15 '09 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

6
1724
by: Rob Meade | last post by:
Lo all, I was just running through some code I was writing for a site and when it came to the 'exact phrase' search type I wasn't sure whether that should run through and ignore the words in the ignore list or not. I ran off and checked your ASPFAQ webby and I notice that Aaron still strips them out, I was just wondering if this is the usual way to deal with that search type, or whether there were good reasons when creating it to still...
6
56812
by: Mark Findlay | last post by:
I am trying to figure out how to set up my reg exp search so that the search will only match on the exact word. Here is the current problem code: Word1 = "RealPlayer.exe" Word2 = "Player.exe" RegExp re = Word2; if (re.Find(Word1))
2
7108
by: Larry | last post by:
I have the following code attached to a search button on a form that runs a query. It works great, except that the search for Last Name only returns exact matches. It is even case sensitive. Anybody have an idea of what I need to add or change. It is the first If Then statement that I need to search on partial matches. I've tried to use the like operator, but I just get syntax errors. If Not IsNothing(Me.LastName) Then strSearch = "= "...
0
2657
by: comp.lang.php | last post by:
I have a form that when you click the "Generate Report" submit button, it will force download a CSV file, required for this project. On the very same page you also have a "Search" submit button, when you press it it should generate search results in a new page. However, when you click the "Generate Report" submit button, the moment you try to THEN click the "Search" submit button, the "Search" submit button NEVER goes to a new page but...
0
1074
by: Kwok | last post by:
I want to search a keyword in a content stored in a table, which the content is a abstract of a report I want to search a keyword by exact word such as: User input : news report The result will only shows content with "news report" instead of "news reporter" I try to add a space to the keyword i.e. SELECT * FROM data WHERE content LIKE '* " + keyword + " '*;" How ever this cannot search the keyword in the beginning of the content and...
4
11227
by: jmdaviault | last post by:
I want to do the equivalent of SELECT id from TABLE WHERE text='text' only fast solution I found is: SELECT id,text from TABLE WHERE MATCH(text) AGAINST('value' IN BOOLEAN MODE) HAVING text='value'
3
1680
by: dbarker1 | last post by:
Hello All, I am developing a web front end using the standard datagrid in the 1.1 framework. Currently it allows users to navigate through records 20 at a time via previous and next buttons. This functionality is working nicely and efficiently. I like this because I dont have to grab ALL the records on each trip, just the next or previous 20. I am having a terrible time creating the exact counts for the data grid navigation. I use a...
3
3273
by: Cli | last post by:
Is it possible to search for exact phrases which include a digit. e.g. "Dublin 1" vrs "Dublin 2" using Mysql fulltext search? As far as I can tell the digits are considered stop words ( too short ) and are ignored. I have a need to search for those exact phrases - spaces included. Thanks.
2
7216
by: Slippy27 | last post by:
I'm trying to modify a find/replace script which iterates through a file A and makes replacements defined in a csv file B. My original goal was to change any line in file A containing a search string (in whole or as a substring) defined in file B. File B contains both the search string and the string it should be changed into. Example file A whippy slippy ippy slippy snoob flop bloppy
0
1884
by: Rilly | last post by:
Anyone use PowerMovielist here? I have the 0.14 beta version. Do you have a problem where some shows you search for cause the fetch to hang ? I'm pulling my hair out on this.. For example, I search for Funky, and it comes up with all the hits.. I search for Funky Phantom, and it hangs for whatever amount of seconds i have the script maximum execution time set to, then i get this error Fatal error: Maximum execution time of 30 seconds...
0
8428
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8335
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8851
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8747
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8627
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7356
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
2752
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1976
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1737
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.