Results 1 to 4 of 4

Thread: SQL/ASP error

  1. #1

    Thread Starter
    Hyperactive Member DKCK's Avatar
    Join Date
    Dec 2000
    Location
    United States
    Posts
    329

    SQL/ASP error

    Some of my fields are names with ' in them (ex: Kelly's Pub, Tom's Place). When I try to do do a query for these names in ASP, the ' in the string causes an error.

    Quick example:
    var = "Kelly's Pub"
    rsRecordSet.Open "SELECT * FROM Ads WHERE Rest = ' " & var & " ';"

    What I end up getting is three ' which doesn't work. Can I replace the two outside ' with another symbol? What is the best way to work around my problem?

  2. #2
    Lively Member
    Join Date
    Jan 2001
    Posts
    118
    Use the replace statement. When you save it to the database. Then you can use SQL to retrieve it.

    PHP Code:
     strings Replace(Exp,"'","''"
    THat is Replace(Exp,','') Double single quoates " ' ".

  3. #3
    Hyperactive Member
    Join Date
    Feb 2001
    Location
    Belgium/Antwerp
    Posts
    275
    You do not have to modify your data to solve the problem, just modify your sql statement.

    Replace the single quotes in the sql string by 2 double quotes like this:

    rsRecordSet.Open "SELECT * FROM Ads WHERE Rest = "" " & var & " "";"

    Your DB will do the translation and wont give any errors on the use of quotes in your variables.

    Greetz, Luc

  4. #4

    Thread Starter
    Hyperactive Member DKCK's Avatar
    Join Date
    Dec 2000
    Location
    United States
    Posts
    329
    Thanks for the answers. I will try them out.

Posting Permissions

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



Click Here to Expand Forum to Full Width