How can I escape an apostrophe inside a SQL query in Google Sheets?
Here's my function:
=QUERY(QUERY(IMPORTRANGE("XXXXXXX", "XXXXXX!A1:C"),"SELECT * WHERE Col2 = 'Woman's blabla: blablabla'"),"SELECT Col1, Col2")
I've tried adding another apostrophe:
=QUERY(QUERY(IMPORTRANGE("XXXXXXX", "XXXXXX!A1:C"),"SELECT * WHERE Col2 = 'Woman''s blabla: blablabla'"),"SELECT Col1, Col2")
No luck.. and I've tried putting a backslash, no luck as well:
=QUERY(QUERY(IMPORTRANGE("XXXXXXX", "XXXXXX!A1:C"),"SELECT * WHERE Col2 = 'Woman/'s blabla: blablabla'"),"SELECT Col1, Col2")
EDIT: The locale of the document is UK.
To escape characters so they aren't treated as part of a regular expression, use the \ character.
Type the formula =char(039) in any cell. It will return the apostrophe character. To replace ' with an apostrophe character use the Find & Replace as below.
Convert a number into a character according to the current Unicode table.
Try using double quotes around the word with the apostrophe
"SELECT * WHERE Col2 = ""Woman's blabla: blablabla"""
If the string you're trying to match is in a cell, try surrounding the cell name with """"
like so:
=QUERY(Foo!A:B,"select A where B = " & """" & A1 & """" & "")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With