String Search with SQL

Ask a Question related to ASP Database, Design and Development.

  1. #1

    Default String Search with SQL

    I was trying to write an SQL statment that will do a string search in an
    Access 2000 database. But I can't seem to figure out how to do it so
    that the search is case-INsensitive. Here's the SQL I have so far:

    SELECT autoQuesID,fldQuesTitle,fldBody
    FROM tblFAQ_Question
    WHERE fldBody LIKE '%airline%';

    All this will do is search for "airline" in lower case. So if the word
    "Airline" is in the field I'm searching in...it won't find it. I've
    also tried this SQL statment:

    SELECT autoQuesID,fldQuesTitle,fldBody
    FROM tblFAQ_Question
    WHERE LCase(fldBody) LIKE '%airline%';

    This won't return any rows, even if there is a match in the field. Can
    anyone help me out?

    Thanks!
    GH Guest

  2. Similar Questions and Discussions

    1. search a string for value
      hi, i have a field that has descriptions for a product.. i want to do a search on this field.. but i'm getting bad results because some users...
    2. how to optimize a string search
      I know this is more of an algorithm question but please bear with me. In my program I am checking wether a emailid exists in a list I have in...
    3. Search string in a file
      On Wed, 15 Oct 2003, Panther wrote: # I must search string in a file ?? # How I must open file in read and search string ?? # What is syntax ??...
    4. String question: Returning portion of string with words surrounding highlighted search term?
      I'm looking to find or create an ASP script that will take a string, examine it for a search term, and if it finds the search term in the string,...
    5. string search
      Is there a way to search a string within a string. For example, I want to search for "world" in "Hello world" knowing that "world" can be anywhere...
  3. #2

    Default Re: String Search with SQL

    GH wrote:
    > I was trying to write an SQL statment that will do a string search in
    > an Access 2000 database. But I can't seem to figure out how to do it
    > so that the search is case-INsensitive. Here's the SQL I have so far:
    >
    > SELECT autoQuesID,fldQuesTitle,fldBody
    > FROM tblFAQ_Question
    > WHERE fldBody LIKE '%airline%';
    >
    > All this will do is search for "airline" in lower case. So if the
    > word "Airline" is in the field I'm searching in...it won't find it.
    Not according to the documentation, or my tests.

    This code:
    <%
    dim cn, rs, sSQL
    set cn=createobject("adodb.connection")
    sSQL="Select * From Table1 WHERE [Name] Like '%home%'"
    cn.open "provider=Microsoft.Jet.OLEDB.4.0;" & _
    "Data Source=" & Server.MapPath("db7.mdb")
    Set rs=cn.Execute (sSQL,,adCmdText)
    Response.Write rs.GetString(adClipString,," | ","<BR>")
    rs.Close:set rs=nothing
    cn.Close:set cn=nothing
    %>

    produced this result:
    9 | Anti-Homeopathy Illuminati | 6


    According to the documentation, all searches are case-insensitive. This
    statement:
    Select * From Table1 WHERE [Name] = 'anti-homeopathy Illuminati'

    produced the same result. It's case-sensitive searches that are hard to do.
    > I've also tried this SQL statment:
    >
    > SELECT autoQuesID,fldQuesTitle,fldBody
    > FROM tblFAQ_Question
    > WHERE LCase(fldBody) LIKE '%airline%';
    >
    > This won't return any rows, even if there is a match in the field.
    > Can anyone help me out?
    >
    I question whether there really is a match. Could you show us the row of
    data that you feel should be returned by this statement?

    Bob Barrows
    --
    Microsoft MVP - ASP/ASP.NET
    Please reply to the newsgroup. This email account is my spam trap so I
    don't check it very often. If you must reply off-line, then remove the
    "NO SPAM"


    Bob Barrows [MVP] Guest

  4. #3

    Default Re: String Search with SQL

    Bob Barrows [MVP] wrote:
    > GH wrote:
    >
    >>I was trying to write an SQL statment that will do a string search in
    >>an Access 2000 database. But I can't seem to figure out how to do it
    >>so that the search is case-INsensitive. Here's the SQL I have so far:
    >>
    >>SELECT autoQuesID,fldQuesTitle,fldBody
    >>FROM tblFAQ_Question
    >>WHERE fldBody LIKE '%airline%';
    >>
    >>All this will do is search for "airline" in lower case. So if the
    >>word "Airline" is in the field I'm searching in...it won't find it.
    >
    >
    > Not according to the documentation, or my tests.
    >
    > This code:
    > <%
    > dim cn, rs, sSQL
    > set cn=createobject("adodb.connection")
    > sSQL="Select * From Table1 WHERE [Name] Like '%home%'"
    > cn.open "provider=Microsoft.Jet.OLEDB.4.0;" & _
    > "Data Source=" & Server.MapPath("db7.mdb")
    > Set rs=cn.Execute (sSQL,,adCmdText)
    > Response.Write rs.GetString(adClipString,," | ","<BR>")
    > rs.Close:set rs=nothing
    > cn.Close:set cn=nothing
    > %>
    >
    > produced this result:
    > 9 | Anti-Homeopathy Illuminati | 6
    >
    >
    > According to the documentation, all searches are case-insensitive. This
    > statement:
    > Select * From Table1 WHERE [Name] = 'anti-homeopathy Illuminati'
    >
    > produced the same result. It's case-sensitive searches that are hard to do.
    >
    >
    >>I've also tried this SQL statment:
    >>
    >>SELECT autoQuesID,fldQuesTitle,fldBody
    >>FROM tblFAQ_Question
    >>WHERE LCase(fldBody) LIKE '%airline%';
    >>
    >>This won't return any rows, even if there is a match in the field.
    >>Can anyone help me out?
    >>
    >
    >
    > I question whether there really is a match. Could you show us the row of
    > data that you feel should be returned by this statement?
    >
    > Bob Barrows
    Ok, here's some data:

    (tblFAQ_Question.fldQuesTitle)
    Row 1: Airline Phone Numbers
    Row 2: How do I make changes to my airline reservations?

    If I type this SQL directly into an access query, I get no results:

    SELECT tblFAQ_Question.fldQuesTitle
    FROM tblFAQ_Question
    WHERE (((tblFAQ_Question.fldQuesTitle) Like '%airline%'));

    This makes even less sense, because now it isn't even finding the row
    that matches it exactly ( row 2).

    GH Guest

  5. #4

    Default Re: String Search with SQL

    GH wrote:
    >
    > If I type this SQL directly into an access query, I get no results:
    >
    > SELECT tblFAQ_Question.fldQuesTitle
    > FROM tblFAQ_Question
    > WHERE (((tblFAQ_Question.fldQuesTitle) Like '%airline%'));
    >
    > This makes even less sense, because now it isn't even finding the row
    > that matches it exactly ( row 2).
    Using the Access Query Builder, you have to use the Jet wildcards (*, ?)
    instead of the odbc wildcards. Your query as typed into the Query Builder
    should look like this (after removing all the unnecessary parentheses and
    aliases):

    SELECT fldQuesTitle FROM tblFAQ_Question
    WHERE fldQuesTitle Like '*airline*'


    It's only when constructing the sql statement using ADO (for example from an
    ASP page) that you need to use the odbc wildcards.

    Bob Barrows

    --
    Microsoft MVP - ASP/ASP.NET
    Please reply to the newsgroup. This email account is my spam trap so I
    don't check it very often. If you must reply off-line, then remove the
    "NO SPAM"


    Bob Barrows [MVP] Guest

  6. #5

    Default Re: String Search with SQL

    Bob Barrows [MVP] wrote:
    > GH wrote:
    >
    >>If I type this SQL directly into an access query, I get no results:
    >>
    >>SELECT tblFAQ_Question.fldQuesTitle
    >>FROM tblFAQ_Question
    >>WHERE (((tblFAQ_Question.fldQuesTitle) Like '%airline%'));
    >>
    >>This makes even less sense, because now it isn't even finding the row
    >>that matches it exactly ( row 2).
    >
    >
    > Using the Access Query Builder, you have to use the Jet wildcards (*, ?)
    > instead of the odbc wildcards. Your query as typed into the Query Builder
    > should look like this (after removing all the unnecessary parentheses and
    > aliases):
    >
    > SELECT fldQuesTitle FROM tblFAQ_Question
    > WHERE fldQuesTitle Like '*airline*'
    >
    >
    > It's only when constructing the sql statement using ADO (for example from an
    > ASP page) that you need to use the odbc wildcards.
    >
    > Bob Barrows
    >
    You're right, when I use the * is does work in the query in access. So
    if I was using PHP, then I would need to use the % instead of the *?

    Thanks again for your help

    GH Guest

  7. #6

    Default Re: String Search with SQL

    GH wrote:
    >
    > You're right, when I use the * is does work in the query in access.
    > So
    > if I was using PHP, then I would need to use the % instead of the *?
    >
    > Thanks again for your help
    I don't know. I've never used PHP. If you use ODBC or OLEDB from PHP, then I
    strongly suspect that you would need to use the odbc wildcards. Can anyone
    confirm this?

    Bob Barrows

    --
    Microsoft MVP - ASP/ASP.NET
    Please reply to the newsgroup. This email account is my spam trap so I
    don't check it very often. If you must reply off-line, then remove the
    "NO SPAM"


    Bob Barrows [MVP] Guest

  8. #7

    Default Re: String Search with SQL

    Bob Barrows [MVP] wrote:
    > GH wrote:
    >
    >
    >>You're right, when I use the * is does work in the query in access.
    >>So
    >>if I was using PHP, then I would need to use the % instead of the *?
    >>
    >>Thanks again for your help
    >
    >
    > I don't know. I've never used PHP. If you use ODBC or OLEDB from PHP, then I
    > strongly suspect that you would need to use the odbc wildcards. Can anyone
    > confirm this?
    >
    > Bob Barrows
    >
    Yup, you're right. I just tried it in PHP and it works with the % and
    not with the *. Thanks!
    GH Guest

Posting Permissions

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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139