Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google Sheets Query Language: escape apostrophe

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.

like image 604
MultiformeIngegno Avatar asked Jan 25 '16 11:01

MultiformeIngegno


People also ask

How do I escape a character in Google Sheets?

To escape characters so they aren't treated as part of a regular expression, use the \ character.

How do I add an apostrophe in Google Sheets?

Type the formula =char(039) in any cell. It will return the apostrophe character. To replace &#039 with an apostrophe character use the Find & Replace as below.

What is the char function in Google Sheets?

Convert a number into a character according to the current Unicode table.


2 Answers

Try using double quotes around the word with the apostrophe

"SELECT * WHERE Col2 = ""Woman's blabla: blablabla"""
like image 89
JPV Avatar answered Sep 19 '22 13:09

JPV


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 & """" & "")

like image 22
Nick Bolton Avatar answered Sep 22 '22 13:09

Nick Bolton