问题
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