Embedding Single Quote in text string in INSERT INTO value

  • In SQL7 I want to include a single quote embedded in a text string to be sent as a field data value:

    Cote D'Ivoire

    When this string gets delimited by single quotes in my INSERT INTO statement, I get a syntax error, as does using doublequote delimiters, or just replacing the embedded single quote by two consecutive ones.

    Can someone please advise precise syntax to solve this?

    Many thanks

    Robin Pearce  

  • Not sure about SQL7, but in SQL Server 2000, you could consider using

    SET QUOTED_IDENTIFIER

    to get round this.

    If you haven't even tried to resolve your issue, please don't expect the hard-working volunteers here to waste their time providing links to answers which you could easily have found yourself.

  • REPLACE(@str,'''','''''')

    Works in SQL 2000, can't say about 7.

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass
  • SET QUOTED_IDENTIFIER solved my problem.

    thanks

    Robin P

  • Using two consecutive single-quotes should always work, where using double-quote to identify a string will be sensitive to the QUOTED_IDENTIFER setting, which I suspect you set to OFF.  I'd recommened in new development you use consecutive single-quotes.

     

    This should always work.

    insert (colname)  select 'Someone''s Name' --two single quotes after "someone"

     

Viewing 5 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic. Login to reply