Question & Answer
Question
How do I identify rows in which the value contains a single quote (') character such as in the name O'Leary?
Answer
To create an SQL query that identifies all rows which have a single quote in its value, you must escape the single quote by using two single quotes.
Examples
To find all rows in a table which have a column named col1 and the value of col1 contains a single quote, use the following SQL:
SELECT * from <table> where col1 like '%''%';
To find all rows in a table which have a column named col1 and the value of col1 = O'Leary, use the following SQL:
SELECT * from <table> where col1='O''Leary';
[{"Product":{"code":"SSULQD","label":"IBM PureData System"},"Business Unit":{"code":"BU053","label":"Cloud & Data Platform"},"Component":"Database","Platform":[{"code":"PF025","label":"Platform Independent"}],"Version":"1.0.0","Edition":"","Line of Business":{"code":"LOB10","label":"Data and AI"}}]
Historical Number
NZ045232
Was this topic helpful?
Document Information
Modified date:
17 October 2019
UID
swg21568936