[Last Call] Learn how to a build a cloud-first strategyRegister Now


Error using a wildcard in a SQL search

Posted on 2005-04-22
Medium Priority
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

Torrwin earned 2000 total points
ID: 13845408
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

ID: 13845490
That worked, thanks

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
Screencast - Getting to Know the Pipeline
Suggested Courses
Course of the Month18 days, 1 hour left to enroll

831 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