Wednesday, March 28, 2012

How to use wildcards in WHERE clause

I have a SQL statement which is generated dynamically. I need to know what is the correct syntax for this

WHERE status = 'open' AND salesman = * AND dat = * AND customername = *

i.e. fetch everything WHERE status = 'open'

I know that simply WHERE status = 'open' would do the trick but I need it like the first example because of the way the statement is being generated i.e. this salesmen bit is like this.

If Salesman <> "*" Then
sql2 &= " AND salesman = '" & Salesman & "'"
Else
sql2 &= " AND salesman = *"
End If

Thanks

BenI presume you are saying that the salesman should be LIKE anything.

You should try:

WHERE status = 'open' AND salesman LIKE '%' AND dat LIKE '%' AND customername LIKE '%'

OleDb uses % as the wildcard character, and you need to use LIKE with wildcards.|||Yes, thats done the trick.

Thanks a lot.

Ben

No comments:

Post a Comment