Muk*_*Ran 22 sql-server-2008 sql-update
我有这个示例T-SQL查询并在SQL-Server-2008上尝试此操作.
DECLARE nvarchar(1000) @wstring = "I asked my son's teacher, "How is my son doing now?""
UPDATE tablename SET columnname = ' " & @wstring & " ' where ... blah ... blah
Run Code Online (Sandbox Code Playgroud)
我知道上面的查询会抛出错误.
那么我如何处理 - 在SQL-Update语句中转义单引号和双引号.
请不要建议在每个报价之前手动添加"斜杠"或单引号,以及bouble-quote.
这是不切实际的,因为上面的示例只是一个sAmple,实际应用程序值超过1000个字符,这将从其他系统源接收.
Rus*_*ser 22
您可以使用反斜杠转义引号:
"I asked my son's teacher, \"How is my son doing now?\""
Run Code Online (Sandbox Code Playgroud)
mcl*_*129 12
使用两个单引号在sql语句中转义它们.双引号应该不是问题:
SELECT 'How is my son''s school helping him learn? "Not as good as Stack Overflow would!"'
Run Code Online (Sandbox Code Playgroud)
打印:
How is my son's school helping him learn? "Not as good as Stack Overflow would!"
| 归档时间: |
|
| 查看次数: |
107234 次 |
| 最近记录: |