how to update column with '

  • hi.

    i need to update the column data with ' mark
    can any one provide the code

    update Person Set First =  O'Brien
    where id =22

    i am getting syntax error

  • You need to use single quote twice.
    O''Brien

    Michael L John
    If you assassinate a DBA, would you pull a trigger?
    To properly post on a forum:
    http://www.sqlservercentral.com/articles/61537/

  • Arjun SreeVastsva - Tuesday, February 21, 2017 1:53 PM

    hi.

    i need to update the column data with ' mark
    can any one provide the code

    update Person Set First =  O'Brien
    where id =22

    i am getting syntax error

    O'Brien is a string, so it should go in quotes. To escape a quote mark, you just add a second one.

    update Person Set First = 'O''Brien'
    where id =22

    Luis C.
    General Disclaimer:
    Are you seriously taking the advice and code from someone from the internet without testing it? Do you at least understand it? Or can it easily kill your server?

    How to post data/code on a forum to get the best help: Option 1 / Option 2
  • the single quote is SQL's delimiter for identifying strings, so you have to escape it by repeating it twice in a row, where you want it to exist inside your string
    update Person Set First = 'O''Brien'
    where id =22

    Lowell


    --help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!

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

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