Results 1 to 3 of 3

Thread: Like operator

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Dec 2003
    Posts
    253

    Like operator

    Hi All,

    I have a table which has several fields and one field is 'Keywords' which hold values to search records, for example, if one record has Keywords such as (Bank, Report, NBFI) and 2nd as (Bank, NBFI, Credit). I am using Access (Like operator) and ASP to fetch data on user typed keywords. So if user input 'Bank' as search keyword. It displays both records but if a user input (Bank, NBFI) it only fetches 2nd record. It doesn't show both records.

    Can any one help me where am I wrong?

    Thanks

  2. #2
    Fanatic Member vb_dba's Avatar
    Join Date
    Jun 2001
    Location
    Somewhere aloft between the real world and insanity
    Posts
    1,016

    Re: Like operator

    When you perform your comparison, you are searching for Like "*Bank, NBFI*". You would need to be able to ammend your query to add a Like clause for each keyword:
    VB Code:
    1. Dim sSql
    2. Dim arrKeyWord
    3. Dim i
    4.  
    5. arrKeyWord = Split(sKeyWordString, ",")
    6.  
    7. sSql = "Select * From myTable Where "
    8. For i = LBound(arrKeyWord) To UBound(arrKeyWord)
    9.     sSql = sSql & "keywordfield Like '*" & arrKeyWord(i) & "*' AND "
    10. Next
    11. 'Remove the trailing AND
    12. sSql = Left(sSql, Len(sSql) - 5)

    Or something to that effect.
    Chris

    Master Of My Domain
    Got A Question? Look Here First

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Dec 2003
    Posts
    253

    Re: Like operator

    Hi thanks for your solution. It works with a little bit of changes.

    Thanks



    Quote Originally Posted by vb_dba
    When you perform your comparison, you are searching for Like "*Bank, NBFI*". You would need to be able to ammend your query to add a Like clause for each keyword:
    VB Code:
    1. Dim sSql
    2. Dim arrKeyWord
    3. Dim i
    4.  
    5. arrKeyWord = Split(sKeyWordString, ",")
    6.  
    7. sSql = "Select * From myTable Where "
    8. For i = LBound(arrKeyWord) To UBound(arrKeyWord)
    9.     sSql = sSql & "keywordfield Like '*" & arrKeyWord(i) & "*' AND "
    10. Next
    11. 'Remove the trailing AND
    12. sSql = Left(sSql, Len(sSql) - 5)

    Or something to that effect.

Posting Permissions

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



Click Here to Expand Forum to Full Width