How do I search for names with apostrophe in SQL Server?

守給你的承諾、 提交于 2019-12-18 18:36:41

问题


SELECT *
  FROM Header
 WHERE (userID LIKE [%'%])

回答1:


Double them to escape;

SELECT *
  FROM Header
 WHERE userID LIKE '%''%'



回答2:


SELECT     *
FROM Header WHERE (userID LIKE '%''%')



回答3:


SELECT *   FROM Header  WHERE userID LIKE '%' + CHAR(39) + '%' 



回答4:


That's:

SELECT * FROM Header 
WHERE (userID LIKE '%''%')



回答5:


Brackets are used around identifiers, so your code will look for the field %'% in the Header table. You want to use a string insteaed. To put an apostrophe in a string literal you use double apostrophes.

SELECT *
FROM Header WHERE userID LIKE '%''%'



回答6:


select * from Header where userID like '%''%'

Hope this helps.




回答7:


Compare Names containing apostrophe in DB through Java code

String sql="select lastname  from employee where FirstName like '%"+firstName.trim().toLowerCase().replaceAll("'", "''")+"%'"

statement = conn.createStatement();
        rs=statement.executeQuery(Sql);

iterate the results.



来源:https://stackoverflow.com/questions/6509159/how-do-i-search-for-names-with-apostrophe-in-sql-server

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!