473,399 Members | 3,888 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

SQL exact search

347 100+
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 2639
CroCrew
564 Expert 512MB
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 Expert 512MB
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 100+
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 Expert 512MB
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
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...
6
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"...
2
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....
0
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,...
0
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...
4
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...
3
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. ...
3
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...
2
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...
0
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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,...
0
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...
0
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,...
0
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...
0
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,...

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.