Start a new topic

How can I use the content of a cell in a mySQL query?


I am using Supermetrics to bring data from mySQL to Google Sheets, but I have a problem. i want the query to have a filter depending on a field. For example, something like where field1='[content of cell A2]'.

How can I do that?

I saw this post:

But I am not able to get it working.

select * from tabla where string_field=%RANGE:'Test sheet'!A1%

returns a syntax error.

How can it be done? Thanks a lot

1 Comment

Hi Héctor,

You can't currently use the %RANGE..% syntax directly in the SQL query string. We'll add support for that in the next few weeks and will let you know when it's available.

In the meantime, you can accomplish the same result by modifying the query in the SupermetricsQueries sheet. Go to the SQL column and insert the range reference like this:

Original SQL: SELECT example FROM some_table WHERE field1='content';

Modified SQL: ="SELECT example FROM some_table WHERE field1='"&'Test sheet'!A2&"';"

Note that if you edit the SQL query in the sidebar, the SQL query string gets static again.

Best regards,

Viktor Djupsjöbacka

Twitter: @Supermetrics 

Support forum:

Login or Signup to post a comment