如何在SQL Server中转义单引号? [英] How do I escape a single quote in SQL Server?
本文介绍了如何在SQL Server中转义单引号?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试insert
一些文本数据到SQL Server
9中的表中.
I'm trying to insert
some text data into a table in SQL Server
9.
文本中包含一个单引号(').
The text includes a single quote(').
我该如何逃避呢?
我尝试使用两个单引号,但是这给我带来了一些错误.
I tried using two single quotes, but it threw me some errors.
例如insert into my_table values(' my name''s tim.');
推荐答案
将单引号加倍即可转义,就像您在示例中向我们展示的一样.以下SQL说明了此功能.我在SQL Server 2008上对其进行了测试:
Single quotes are escaped by doubling them up, just as you've shown us in your example. The following SQL illustrates this functionality. I tested it on SQL Server 2008:
DECLARE @my_table TABLE (
[value] VARCHAR(200)
)
INSERT INTO @my_table VALUES ('hi, my name''s tim.')
SELECT * FROM @my_table
结果
value
==================
hi, my name's tim.
这篇关于如何在SQL Server中转义单引号?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文