Error using a wildcard in a SQL search

Posted on 2005-04-22
Last Modified: 2010-04-23
I have a text box that takes input from a user and I want to use that information to do a SQL search.  I am searching on last name and I would like them to be able to do a partial search.

My current SQL statement is:
SELECT DISTINCT str_agent_number, str_agent_fname, str_agent_lname, num_agent_code, str_location_code, num_mbc_code, num_territory_number, str_address, str_city, str_zip, str_phone_number, str_state FROM tbl_sro_boatdeck INNER JOIN tbl_state_code_lookup ON tbl_sro_boatdeck.num_state_code = tbl_state_code_lookup.num_state_code WHERE tbl_sro_boatdeck.str_agent_lname LIKE '" & txtLName.Text & "'"

When I put a % sign on either side of 'txtLName.Text' I receive an invalid character error.  Please advise.  thanks.
Question by:freethinker23
    LVL 13

    Accepted Solution

    you need to do it like this:

    LIKE '%" & txtLName.Text & "%'"

    If you are doing this and still recieving an error its not the % sign.  Make sure you have the correct number of quote marks ".  You're missing one at the beginning of your statement.

    Author Comment

    That worked, thanks

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Why You Should Analyze Threat Actor TTPs

    After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

    This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
    The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (…
    To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…
    Internet Business Fax to Email Made Easy - With eFax Corporate (, you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

    759 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    11 Experts available now in Live!

    Get 1:1 Help Now