2014-10-30 58 views
-2

我有从表像检查字符串与SQL

Select email from cust Where name = " John carter's " 

我得到的错误是由于字符串单引号获取值查询特殊字符....

请帮助我的上述问题

+1

可能的重复[如何在SQL Server中转义单引号?](http://stackoverflow.com/questions/1586560/how-do-i-escape-a-single-quote-in-sql-服务器) – 2014-10-30 19:43:28

回答

2

这应该工作:

Select email from cust Where name = " John carter''s" 
+0

如果我有这种类型的查询,然后从客户端选择电子邮件Where name ='约翰卡特的' – user3656418 2014-10-30 19:48:05

+0

@ user3656418在这种情况下,在您的第二个单引号之前添加其他'''像这样:'从cust选择电子邮件Where name =“John carter”的“'”' – 2014-10-30 19:50:17

+1

这是正确的。 – Hituptony 2014-10-30 19:51:03

0

如果这是你只是需要一些拿到现在...

Select email from cust Where name LIKE "%John carter%" 

,或者你可以逃脱撇号:你为什么不使用转义字符

Select email from cust Where name = " John carter''s" 
+0

如果我有这种类型的查询,然后从客户端选择电子邮件Where name ='约翰卡特的' – user3656418 2014-10-30 19:48:51

0

像这样

Select email from cust Where name = " John carter''s " 
+0

如果我有这种类型的查询,然后从客户端选择电子邮件Where name ='约翰卡特的' – user3656418 2014-10-30 19:48:33

0

您遇到的问题是由(取决于数据库您正在使用的程序)的单引号'是一个SQL数据建模语言造成的事实(DML)分隔符,所以SQL解析器可能无法正确处理它。