Results 1 to 9 of 9

Thread: [RESOLVED] Parameters in Query Using "LIKE" statement

  1. #1

    Thread Starter
    Fanatic Member The_Grudge's Avatar
    Join Date
    Jan 2005
    Location
    Canada
    Posts
    836

    Resolved [RESOLVED] Parameters in Query Using "LIKE" statement

    I'm sure I have a few issues in this statement, but I believe my main issue comes from where my "LIKE" statement resides.

    I'm using parameters in VB 6 -- hence my post to this forum and not the database forum. Apologies if that assumption is wrong.

    Anyway, here's what I have and it's not currently working.

    Code:
      strSQL = "SELECT PROD.CSU_Clinic_Info.Clinic_Date, PROD.CSU_Clinic_Info.SID_DOC_NUM, " & _
                  "PROD.CSU_Clinic_Info.Day_Of_Week, PROD.CSU_Clinic_Info.ID " & _
                  "FROM PROD.CSU_Clinic_Info " & _
                  "WHERE (PROD.CSU_Clinic_Info.Clinic_Date >= ? " & _
                  "AND PROD.CSU_Clinic_Info.Clinic_Date <= ?) " & _
                  "AND PROD.CSU_Clinic_Info.Id Like %? " & _
                  "AND LEN(PROD.CSU_Clinic_Info.ID) = Len(?) " & _
                  "AND PROD.CSU_Clinic_Info.Day_Of_Week = ? " & _
                  "AND PROD.CSU_Clinic_Info.Cancelled <> 'Y' " & _
                  "AND PROD.CSU_Clinic_Info.Institution = ? " & _
                  "ORDER BY CLINIC_DATE ASC"
    It returns Incorrect syntax near '@P3'

  2. #2
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: Parameters in Query Using "LIKE" statement

    Can you tell us what the parameter value is?
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  3. #3

    Thread Starter
    Fanatic Member The_Grudge's Avatar
    Join Date
    Jan 2005
    Location
    Canada
    Posts
    836

    Re: Parameters in Query Using "LIKE" statement

    It's a string. Value is "97"

  4. #4
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: Parameters in Query Using "LIKE" statement

    Initial thought: Instead of... Like %?
    Maybe... Like '%' + ?
    Or including the % in the parameter value?
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  5. #5

    Thread Starter
    Fanatic Member The_Grudge's Avatar
    Join Date
    Jan 2005
    Location
    Canada
    Posts
    836

    Re: Parameters in Query Using "LIKE" statement

    I think I got it. One of my parameters was incorrect. Seems to be okay now.

  6. #6

    Thread Starter
    Fanatic Member The_Grudge's Avatar
    Join Date
    Jan 2005
    Location
    Canada
    Posts
    836

    Re: Parameters in Query Using "LIKE" statement

    Quote Originally Posted by The_Grudge View Post
    I think I got it. One of my parameters was incorrect. Seems to be okay now.
    Seems I was mistaken. Query runs but doesn't return matches -- and it should. If I hard code a value in it works so something about that "LIKE" it doesn't -- ahem -- like.

    Here's what I had to do to get it working....that Like statement looks like this

    AND PROD.CSU_Clinic_Info.Id Like '%' + ?
    Last edited by The_Grudge; May 31st, 2018 at 12:23 PM.

  7. #7
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: [RESOLVED] Parameters in Query Using "LIKE" statement

    So, your recordset has both EOF & BOF set to true?

    Maybe you can re-post your query and the parameter values, for each parameter. We might find something that looks iffy?

    I'd also suggest running a simpler query with just the LIKE statement/criteria. If it returns records then one or more of your other criteria is not being met.

    Edited: I probably should've refreshed before I posted. Sounds like you found the solution. Your solution, by the way, was what I suggested in post #4 above.
    Last edited by LaVolpe; May 31st, 2018 at 12:43 PM.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  8. #8
    PowerPoster Zvoni's Avatar
    Join Date
    Sep 2012
    Location
    To the moon and then left
    Posts
    5,268

    Re: Parameters in Query Using "LIKE" statement

    Quote Originally Posted by The_Grudge View Post
    AND PROD.CSU_Clinic_Info.Id Like '%' + ?
    Question: is that column of type text or numeric?
    i was always under the impression that LIKE only works on text-patterns.

    if text, i would expect something like

    AND PROD.CSU_Clinic_Info.Id Like '% + ? +%'
    Last edited by Zvoni; Tomorrow at 31:69 PM.
    ----------------------------------------------------------------------------------------

    One System to rule them all, One Code to find them,
    One IDE to bring them all, and to the Framework bind them,
    in the Land of Redmond, where the Windows lie
    ---------------------------------------------------------------------------------
    People call me crazy because i'm jumping out of perfectly fine airplanes.
    ---------------------------------------------------------------------------------
    Code is like a joke: If you have to explain it, it's bad

  9. #9
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: Parameters in Query Using "LIKE" statement

    Quote Originally Posted by Zvoni View Post
    Question: is that column of type text or numeric?
    i was always under the impression that LIKE only works on text-patterns.
    I actually had that question myself and tested the LIKE on a numeric field (even fields that contained NULL values). No problem in SQL Server which is what I'm assuming that the_grudge is using.

    I also wondered about not having the wild card suffixed. Just assumed he was looking for values that ended with 97.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

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