How do you insert a row with a single quote '

  • Hi

    How do you insert a row into a table where one of the column has single quote ' as a part of the columns data.

    For eg.

    Create table a1 (a varchar(3000))

    insert into a1 values ('This is Soumil's laptop')

    How do we go about insert this row which obviously has a single quote which marks the end of character string?

    Thanks for your help.

    -Soumil

  • You need to escape the single quote with another single quote like this.

    insert into a1 values('This is Soumil''s laptop')

  • this works:

    SET QUOTED_IDENTIFIER OFF

    GO

    Create table #a1 (a varchar(3000))

    insert into #a1 values ("This is Soumil's laptop")

    select * from #a1

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

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