Google Sheets Query Language: escape apostrophe

拥有回忆 提交于 2019-12-01 03:36:54

问题


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.


回答1:


Try using double quotes around the word with the apostrophe

"SELECT * WHERE Col2 = ""Woman's blabla: blablabla"" "




回答2:


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




回答3:


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:



来源:https://stackoverflow.com/questions/34991998/google-sheets-query-language-escape-apostrophe

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!