|
-
May 31st, 2018, 09:16 AM
#1
Thread Starter
Fanatic Member
[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'
-
May 31st, 2018, 09:19 AM
#2
Re: Parameters in Query Using "LIKE" statement
Can you tell us what the parameter value is?
-
May 31st, 2018, 09:21 AM
#3
Thread Starter
Fanatic Member
Re: Parameters in Query Using "LIKE" statement
It's a string. Value is "97"
-
May 31st, 2018, 09:22 AM
#4
Re: Parameters in Query Using "LIKE" statement
Initial thought: Instead of... Like %?
Maybe... Like '%' + ?
Or including the % in the parameter value?
-
May 31st, 2018, 09:32 AM
#5
Thread Starter
Fanatic Member
Re: Parameters in Query Using "LIKE" statement
I think I got it. One of my parameters was incorrect. Seems to be okay now.
-
May 31st, 2018, 12:02 PM
#6
Thread Starter
Fanatic Member
Re: Parameters in Query Using "LIKE" statement
 Originally Posted by The_Grudge
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.
-
May 31st, 2018, 12:30 PM
#7
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.
-
May 31st, 2018, 02:07 PM
#8
Re: Parameters in Query Using "LIKE" statement
 Originally Posted by The_Grudge
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
-
May 31st, 2018, 02:12 PM
#9
Re: Parameters in Query Using "LIKE" statement
 Originally Posted by Zvoni
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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|