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.
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 & """" & "")
Try substituting the double quotes in the source data through the function, you may need to swap out some of the quotes i added - I dont know what the text your searching for actually looks like in your source data:
=QUERY(QUERY(IMPORTRANGE("XXXXXXX", SUBSTITUTE("XXXXXX!A1:C","""","'")),"SELECT * WHERE Col2 = 'Woman's blabla: blablabla'"),"SELECT Col1, Col2")
EDIT: