SQL Syntax

thandel
thandel used Ask the Experts™
on
I am trying to run an SQL command ... I have it working as:

sSql = "SELECT * FROM tClaim WHERE ClaimNo = " & """" & sLab & """"

but I need to do a wild card search and trim the variable..... so I tried this:

sSql = "SELECT * FROM tClaim WHERE ClaimNo Like "" * "" & Trim(sLab) & "" * """

This just ends up freezing up MS Access.

What is wrong with my SQL statement looking for a wild card?

Thank you.
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Software Engineer
Top Expert 2011
Commented:
Drop the equals sign, Try
sSql = "SELECT * FROM tClaim WHERE ClaimNo Like " & "'*" & Trim(sLab) & "*'"

Open in new window

Ryan ChongSoftware Team Lead

Commented:
try like:

sSql = "SELECT * FROM tClaim WHERE ClaimNo Like '*" & Replace(Trim(sLab),"'","''") & "*' "

Open in new window

Author

Commented:
Thanks I edited my question and had removed the equal sign but missed the single quotes.... that worked thanks Paul!
Ryan ChongSoftware Team Lead

Commented:
anyway...

this part :  

Like " & "'*" 

Open in new window


can be simplified to as what I already shown

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial