2011-10-10 53 views
1

单引号我有以下查询问题在SQL SERVER竟能在SQL Server查询

select ecode,ename 
    from VW_EFORMS_BillingAdjustmentCodes 
where ename='Ravi's friend'; 

在上面的查询“拉维的朋友”是从数据库的字符串。我可以逃脱单引号 请帮我..

+0

可能重复在sqlserver?](http://stackoverflow.com/questions/1586560/how-do-i-escape-a-single-quote-in-sqlserver) – Praveen

回答

2

字符串中的单引号会被连续两个单引号('')转义。

where ename='Ravi''s friend' 
       ^^ two '' 
4

您可以使用两个引号:

'Ravi''s friend' 

或者使用参数化查询并提供字符串作为参数:

SELECT ecode, ename 
FROM VW_EFORMS_BillingAdjustmentCodes 
WHERE ename = ? 
的[我如何逃脱一个单引号
+1

+1的参数建议! –