How to Search for Names with Apostrophe in SQL Server

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

Double them to escape;

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

SQL to Query text in access with an apostrophe in it

You escape ' by doubling it, so:

Select * from tblStudents where name like 'Daniel O''Neal' 

Note that if you're accepting "Daniel O'Neal" from user input, the broken quotation is a serious security issue. You should always sanitize the string or use parametrized queries.

SQL 'LIKE' clause with apostrophe

This will work:

 [Team] LIKE '%RYAN''S TEAM%' 

You just have to double the quote chars.

How to I search for a single quote character( ' ) in a text Using LIKE predicate in SQL Server

CREATE TABLE #TEST
( Test_Column VARCHAR(MAX));

INSERT INTO #TEST VALUES
('10011-RIO MARE EXTRA''')

SELECT *
FROM #TEST
WHERE Test_Column LIKE '%''%'

The escape character for ' is ' used twice -> ''.

How to use apostrophe in LIKE operator on a WHERE clause? Example - WHERE WORD like '%That's why%'

WHERE WORD like '%That''s why%'

Example (SQL Server):

Sample Image



Related Topics



Leave a reply



Submit