PDA

View Full Version : Wildcard in SQL



lifeson
03-20-2009, 02:07 AM
Hi folks
Not been on for a while :hi:

How do I use a wildcard value in an SQL

heres my SQL
Private Sub BuildList(cGroup As String, cType As String, active As Boolean)
Dim qry As String
Dim idx As Long, icon As Long

qry = "SELECT TblComponentDetail.ComponentID, TblComponentDetail.ComponentGroupID, " & _
"TblComponentDetail.ComponentTypeID, TblComponentDetail.ActiveToDate, " & _
"TblComponentDetail.Description, TblComponentDetail.ActiveFlag, TblComponentDetail.Make, " & _
"TblComponentDetail.Model " & _
"FROM TblComponentDetail " & _
"WHERE (((TblComponentDetail.ComponentGroupID)='" & cGroup & "') " & _
"AND ((TblComponentDetail.ComponentTypeID)='" & cType & "') " & _
"AND ((TblComponentDetail.ActiveToDate)>Now()) " & _
"AND ((TblComponentDetail.ActiveFlag)=True));"

If I dont know cType when I run the SQL what value should I use to represent cType when calling the routine e.g.

Call BuildList(cGroup, "*", True)

I have tried
like"*" but that comes up with a mismatch error
I have tried just * and _
but no joy.

Charlize
03-20-2009, 02:34 AM
Probably not the best solution but what about an if clause to check if ctype is known. If it's blank, don't include this field in your query and perform the query without this field.

Charlize

Jan Karel Pieterse
03-20-2009, 02:42 AM
Try % instead of * and _ instead of ?