Register

If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Results 1 to 3 of 3
  1. #1
    Junior Member
    Join Date
    Sep 2007
    Posts
    6
    Member #
    15789
    Hey guys,
    I've created my first search page using ASP. Whilst the search function works and data can be obtained, the results will only be successful if the word i try to search is the first word in any entry in one field.
    For example...
    if i search for BALL
    i will get nothing...
    however if i search for GLOW BALL i will get a result
    i will receive a result...
    similarly if i search for GLOW i will get multiple results?

    How can i structure the query so that i can search for any of the words within the field and be guaranteed to get a result?
    the link for the search form is
    http://www.galaxyworldimports.com.au/search.html

    Thanks for any help!!

    a sample of the asp code is listed below:
    Code:
    ]<%
     'Open up a connection to our Access Database
     'that stores the customer information.
     Set MyConn = Server.CreateObject("ADODB.Connection")
          MdbFilePath = Server.MapPath("Databases/gal_imports.mdb")
          MyConn.Open "Driver={Microsoft Access Driver (*.mdb)}; DBQ=" & MdbFilePath & ";"
     
     'Read in the charactes the user entered
     Dim strProductNameQ
     strProductNameQ = Trim(Request("ProductNameQ"))
     
     'Create our SQL statenebt variable
     Dim strSQL
     strSQL = "SELECT ProductName, ProductPrice FROM Products WHERE ProductName LIKE '" & _ 
      strProductNameQ & "%' ORDER BY ProductName"
     
     'Create a recordset object instance, and execute the SQL Statement
     Dim objRS
     Set objRS = Server.CreateObject("ADODB.Recordset")
     objRS.Open strSQL, MyConn
     
     'Determine whether or not there are any records in objRS
     If objRS.EOF then
      'No records were returned for the characters entered by the user
      Response.Write "There are no products that contain " & _ 
       UCase(strProductNameQ)
     
     Else
      'There are one or more products that meet the condition entered by the
      'user. Display these products...
     
      Response.Write "<B>A Listing of Products beginning with " & _
       UCase(strProductNameQ) & ":</B><BR>"
     
      Do While Not objRS.EOF
       Response.Write objRS("ProductName") & " - " & _ 
         FormatCurrency(objRS("ProductPrice")) & "<BR>"
     
     
       'Move on to the next customer
       objRS.MoveNext
      Loop
     End If
     
     'Clean up our ADO objects
     objRS.Close
     Set objRS = Nothing
     
     MyConn.Close
     Set MyConn = Nothing
     
     %>

  2.  

  3. #2
    Senior Member
    Join Date
    May 2003
    Location
    UK
    Posts
    2,354
    Member #
    1326
    Try
    Code:
    strSQL = "SELECT ProductName, ProductPrice FROM Products WHERE ProductName LIKE '%" & _ 
      strProductNameQ & "%' ORDER BY ProductName"
    Change in red.

  4. #3
    Junior Member
    Join Date
    Sep 2007
    Posts
    6
    Member #
    15789
    Quote Originally Posted by bfsog
    Try
    Code:
    strSQL = "SELECT ProductName, ProductPrice FROM Products WHERE ProductName LIKE '%" & _ 
      strProductNameQ & "%' ORDER BY ProductName"
    Change in red.
    Thats Perfect!! Thanks very much!!


Remove Ads

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

Search tags for this page

how to search one word sql
,
search in sql database for multiple terms
,
searching multiple words in sql
,
sql find word in field
,
sql mix of words in field
,
sql query two words in field
,
sql search for several words
,
sql search more than one word
,

sql search multiple words

,
sql to find muiltiple words
Click on a term to search for related topics.
All times are GMT -6. The time now is 10:15 AM.
Powered by vBulletin® Version 4.2.3
Copyright © 2019 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com