如何使用单引号SQL Server 2005插入文本 [英] How to insert text with single quotation sql server 2005

查看:130
本文介绍了如何使用单引号SQL Server 2005插入文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要插入带单引号的文本 例如,约翰到SQL Server 2005数据库中的表

I want to insert text with single quote Eg john's to table in sql server 2005 database

推荐答案

转义单引号,如Kirtan指出的那样加上单引号
而且,如果您尝试通过sp_executesql执行动态sql(首先不是一个好主意),则下面的代码将为您工作

Escape single quote with an additional single as Kirtan pointed out
And if you are trying to execute a dynamic sql (which is not a good idea in the first place) via sp_executesql then the below code would work for you

sp_executesql N'INSERT INTO SomeTable (SomeColumn) VALUES (''John''''s'')'

这篇关于如何使用单引号SQL Server 2005插入文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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