SQL query in ASP

Results 1 to 3 of 3

Thread: SQL query in ASP

  1. #1
    Simon Herman Guest

    Default SQL query in ASP

    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
    Join Date
    Dec 1969

    Default RE: SQL query in ASP

    Use Replace(Request.form("NAME"), "&#039", "&#039&#039") <BR><BR>&#039&#039 means just one in SQL<BR><BR>Good Luck<BR><BR>Brandon

  3. #3
    Join Date
    Dec 1969

    Default RE: Beware the " & Wildcard combo !

    Be aware that in MS SQL7 if you use the " to replace the &#039 in strings, if you use the " and follow it with a wildcard you can get freaky results. Assuming you want to use the " Mark do error checking in your code to insure that there is another non-wildcard character after the ". The alternative is to use the syntax:<BR><BR>Select * From Pubs Where au_lname= &#039O&#039+Char(39)+&#039%&#039 <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