How do I escape a single quote in SQL Server?

前端 未结 13 1850
情话喂你
情话喂你 2020-11-21 07:01

I\'m trying to insert some text data into a table in SQL Server 9.

The text includes a single quote(\').

How do I escape that?

13条回答
  •  难免孤独
    2020-11-21 07:20

    2 ways to work around this:


    for ' you can simply double it in the string, e.g. select 'I''m happpy' -- will get: I'm happy


    For any charactor you are not sure of: in sql server you can get any char's unicode by select unicode(':') (you keep the number)

    So this case you can also select 'I'+nchar(39)+'m happpy'

提交回复
热议问题