Apostrophes wreaking havoc with SQL queries...

Results 1 to 3 of 3

Thread: Apostrophes wreaking havoc with SQL queries...

  1. #1
    John H. H. Guest

    Default Apostrophes wreaking havoc with SQL queries...

    Hi all,<BR><BR>I have a problem. When using SQL query with ASP to search a database, how does one handle a search criterium that contains an apostrophe? For instance, let&#039s say I am searching the FirstName and LastName fields of a table. The search criteria are John and O&#039Connor. The SQL query below would fail because of the apostrophe in O&#039Connor.<BR><BR>SELECT * FROM names WHERE firstname=&#039john&#039 AND lastname=&#039o&#039connor&#039<BR><BR>How do I remedy this? Any help would be greatly appreciated.<BR><BR>Thanks.<BR><BR>JHH

  2. #2
    Join Date
    Dec 1969
    Posts
    175

    Default RE: Apostrophes wreaking havoc with SQL queries...

    You will have to put two apostrphes to indicate one <BR>apostrophe<BR><BR>So ur SQL will be<BR><BR>SELECT * FROM names WHERE firstname=&#039john&#039 AND lastname=&#039o&#039&#039connor&#039<BR><BR>

  3. #3
    John H. H. Guest

    Default RE: Apostrophes wreaking havoc with SQL queries...

    Thanks, it worked like a charm!<BR><BR>JHH

Posting Permissions

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