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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Not able to search for the # character in my ASP SQL statement

Status
Not open for further replies.

ggs54

Programmer
Apr 7, 2003
8
US
I have a database with a size field in it. That field contains both the single-quote (') and the pound sign (#). I have a search form set up and it works properly with one exception. Whenever I use the # sign, it appears that the query doesn't recognize it. No error is generated and no records are found. The # sign can be located anywhere in the field e.g. #5 or 5-6#

I have tried many variations on the SQL statement with no luck. Here are a couple of my attempts.

...AND Size LIKE '%::Size::%')"
...AND Size LIKE '%Size%')"

The SQL manual that I have gives an example of escaping a character using the ESCAPE clause in the SQL statement e.g.
...AND Size LIKE '%Size%' ESCAPE '#')"
This produces a syntax error and I am assuming that my IIS server doesn't recognize the ESCAPE keyword.

Any thoughts?
 
What is the Size thing in you sql?

if its an asp variable you need to do it like this:

...AND Size LIKE '%" & Size & "%'"
 
Size is the field name in the form that I am collecting user input from.

In addition to the two examples on my original message, I have tried the following with no luck.

...AND Size LIKE '%::" & Request.Form("Size") & "::%')"
...AND Size LIKE '%" & Request.Form("Size") & "%')"

strSize = Request.Form("Size")
...AND Size LIKE '%" & strSize & "%')"

This last example works correctly, except if the user includes a # sign in their input. If they input #5, no records are returned. If they input only the # sign, 100 records are returned, which is my designated maximum, regardless of what is contained in the size field. It's as if the # sign was being ignored.
 
you are going to have trouble because the like operator expects the # sign to mean any single digit.

you can try

try replacing the users input # with [#]. That might work.

i.e.

tosearch = Request("size")
Replace(search,"#","[#]") (note: i might not have syntax correct)
..." and size like '%" & tosearch & "%')"
 
Hi, unseth.

Your suggestion works perfectly! I can't believe that this isn't documented in my FrontPage, ASP or SQL manuals. I did find it in my VB manual and , since this is my first ASP project, didn't think to look their.

Thanks, again.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top