INSERT column value with imbedded apostraphe

  • Using the following sample, how can I INSERT a column value that contains an apostraphe w/in the CountryName?

    Countries  CountryCode INT, CountryName nvarchar(256)

    insert into Countries (CountryCode, CountryName)

     values (5, 'Cote D'Ivoire')

    (Notice the imbedded apostraphe in the value:  D'Ivoire)

    thx-

    BT
  • insert into Countries (CountryCode, CountryName)

     values (5, 'Cote D''Ivoire')

    Should do it.

    Prasad Bhogadi
    www.inforaise.com

  • SET NOCOUNT ON

    DECLARE @Countries TABLE

    (

    CountryCode INT,

    CountryName VARCHAR(100)

    )

    INSERT INTO @Countries VALUES (1, 'Country Name 1')

    INSERT INTO @Countries VALUES (5, 'Cote D''Ivoire')

    SELECT * FROM @Countries

    Regards,
    gova

  • replace the apostrophe with 2 single quotes to indicate that it is a literal value...

    insert into Countries (CountryCode, CountryName)

    values (5, 'Cote D''Ivoire')







    **ASCII stupid question, get a stupid ANSI !!!**

  • Actually, to add to this...

    Every time you have another level of nested single quotes, you have to double the number of them you use.  I ran across this when I had to write a query similar to yours, but the entire text of the query was a string in my code.  So the result was something like:

    'INSERT INTO @Countries VALUES (5, ''Cote D''''Ivoire'')'


    Two muffins are sitting in an oven. The first one turns to the second and says "pretty hot in here, huh?"
    The second muffin glances at the first and then shrieks in fear,
    "AAAAAAHH!!! A TALKING MUFFIN!!!"

  • you might want to try this

    insert..... 'Cote D' + char(39) + 'Ivoire'

    I find that easier than keeping track of how many single quotes I need to type.

     

    Sara

     

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

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