Problem with wildcards and " ' "

Results 1 to 4 of 4

Thread: Problem with wildcards and " ' "

  1. #1
    Simon Herman Guest

    Default Problem with wildcards and " ' "

    I have wrriten an ASP page that runs a sql query to an access database.<BR><BR>The query is based on input from a user form. If the user puts in the first couple of letters of someone&#039s name, it then produces a list of similar named people.<BR><BR>The problem part of the query is <BR>...AND((ALPHA.Name) LIKE &#039" & Request.QueryString("name") & "%&#039)<BR>Where ALPHA is the ODBC source, Name is the field within the source and name is one of the search criteria.<BR><BR>It all works fine until you try to put in the first part of a name that contains an apostrophe eg. "O&#039Co", at which point it returns a syntax error containing AND((ALPHA.Name) alike &#039o&#039%<BR><BR>help!

  2. #2
    Neil Popham Guest

    Default RE: Problem with wildcards and

    try the following:<BR><BR>&#062; strName = Request.QueryString("name")<BR>&#062; strName = Replace(strName, "&#039", "&#039&#039")<BR><BR>and use "...AND((ALPHA.Name) LIKE &#039" & strName & "%&#039)<BR><BR>ie: this will replace single apostrophes with 2 apostrophes (nb: NOT 1 quote mark - may be best to cut&#039n&#039paste into a monospaced font to see what i mean)<BR><BR>are you sure ALPHA is the ODBC source and not the table name?

  3. #3
    Simon Herman Guest

    Default RE: Problem with wildcards and

    Actually ALPHA is both.<BR>That worked, thanks. If you have time, could you briefly explain the mechanics of how it works - I think I understand, but I&#039m not sure.<BR><BR>Simon

  4. #4
    Neil Popham Guest

    Default RE: Problem with wildcards and

    uummm... not really simon. it just works... it is the correct &#039syntax&#039<BR><BR>you can also use the same method for quote marks, so if you need to write quote marks in a response.write:<BR><BR>Response.Write "&#060;a href=""page.htm""&#062;link&#060;/a&#062;"<BR><BR>will output:<BR><BR>&#060;a href="page.htm"&#062;link&#060;/a&#062;<BR><BR>to the page.<BR><BR>If you enquiring regarding the syntax of the REPLACE function i would suggest you download the VBScript v5 docs at:<BR><BR><BR><BR>download the &#039help update package&#039 and the 32bit VBScript doc.<BR><BR>VERY helpful - cant recommend it enough if you dont have it.<BR><BR><BR><BR>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts