Results 1 to 6 of 6

Thread: SQL with wildcard?

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Aug 2000
    Posts
    1,091
    Hi,

    I'm trying to construct a "wildcard" SQL statement such as:

    Code:
    Dim sSQL as String
    Dim sSearchFor as String
    
    sSearchFor = Text1.Text
    
    sSQL = "SELECT * " _
         & "FROM tblTest " _
         & "WHERE Field1 LIKE '*" & sSearchFor & "*'"
    
    Set rs = New RecordSet
    
    rs.Open sSQL, db
    The idea being that the user can enter any text in Text1 and it will find any record where Field1 contains the text that the user entered..

    But, it does not seem to be returning any records. It does not seem to like the wildcards.. It doesn't error out, but it just doesn't return any records... And yes, I have verified that the text does in fact exist in the database.. When I remove the * signs, then the records are returned, if I enter the whole Field1 text..

    Any idea on how to make this thing work?

    Thanks,

    Dan

  2. #2
    Guest
    try this:

    Code:
    Dim sSQL as String
    Dim sSearchFor as String
    
    sSearchFor = Text1.Text
    
    sSQL = "SELECT * FROM tblTest " _
        & "WHERE Field1 LIKE '%" & sSearchFor & "%'"
    
    Set rs = New RecordSet
    rs.Open sSQL, db
    cause when using LIKE in SQL, the % sign that comes in front of or behind (a) letter(s) stands for the wildcard.

  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Aug 2000
    Posts
    1,091
    Thank you, that worked!!!

    Dan

  4. #4
    Guest
    no prob. glad to have helped.

  5. #5
    Frenzied Member
    Join Date
    Aug 1999
    Location
    Santa Clara, Ca , 95058
    Posts
    1,105
    It's going to depend on the DBMS and what you use to access it. Microsoft Access (with DAO) will use the "*" in place of the "%"

  6. #6
    Lively Member
    Join Date
    Aug 2000
    Location
    Texas
    Posts
    88
    More information

    I have used a "*" for query like that and it works fine for me. I use ADO and SQL Server 7.0.

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