如何在 SQL-Update 语句中处理转义单引号和双引号 [英] How to handle-escape both single and double quotes in an SQL-Update statement

查看:41
本文介绍了如何在 SQL-Update 语句中处理转义单引号和双引号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个示例 T-SQL 查询并在 SQL-Server-2008 上尝试这个.

I have this sample T-SQL query and trying this on 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

我知道上面的查询会抛出错误.

I know that the above query will throw error.

那么如何在 SQL-Update 语句中处理转义单引号和双引号.

So how do I handle-escape both single and double quotes in an SQL-Update statement.

推荐答案

你可以用反斜杠转义引号:

You can escape the quotes with a backslash:

"I asked my son's teacher, \"How is my son doing now?\""

这篇关于如何在 SQL-Update 语句中处理转义单引号和双引号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆