Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Minor SELECT query issue 2

Status
Not open for further replies.

gchaves

Programmer
Oct 27, 2003
105
US
Hello!

I have a SELECT query that is used to search business names in a database. In some cases, it works...in others, it doesn't. Here is what I mean:

It works if there is no special characters such as ' , & . etc.

BUT...if someone enters a business name of (for example) Dewey, Cheetam & Howe OR Dewey's Business then the search does not find the business name (even though it is in the database).

My SELECT query (for simplicity) reads as:

leadSrch=Request.Form("bus_name")

sqlLeadSrch="SELECT * FROM requests WHERE bus_name = '" & leadSrch & "';"

I know I'm probably missing something very minor...but is there a way to get my SELECT query to pull records that contain business names such as Dewey, Cheetam & Howe?

Any help or advice or google search would be greatly appreciated!

thanks...G!
 
You dont need that semicolon, for one. You may also want to trim to avoid problems with spacing.

Code:
sqlLeadSrch="SELECT * FROM requests WHERE bus_name = '" & Trim(leadSrch) & "'"

If that doesn't help do this...
Response.WRite sqlLeadSrch
and then go to your DB and paste in whatever it says. That'll be a dead giveaway most likely.
 
Thank you much for the quick response! Upon further examination of the table(s) in my database, I realized what my problem was...although I do agree with your advice. I have two additional fields in my query that can accept zero length values. So, when my query was doing a search on a record that had zeros in these two fields, it wasn't displaying the information.

Your advice definitely deserves a star! Thanks again!
 
I want to create ASP and connect it to Database. If anyone can help me, please e_mail dhaka144@yahoo.com
Thank you.
sincerely,

Arif Khan
 
To get around the invalid characters replace a single quote with two single quotes and then you wont have to worry about it. No need to change it back because it will output it back out as one single quote.

sText = Replace(sText,"'","''")

- Jason

www.sitesd.com
ASP WEB DEVELOPMENT
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top