Using Cell References In MySQL Queries

When working with Two Minute Reports and running queries, you might find yourself needing to tweak your queries regularly. Whether itā€™s adjusting the date range in the WHERE clause or applying a status filter, manually changing the SQL query each time can be time-consuming.

Fortunately, thereā€™s a solution: Using cell references in your SQL query you can dynamically update your queries based on values from the Spreadsheetā€™s cell value. Letā€™s see how to use them:

Steps

1. Connect to your data source and set up your query as you normally would. If you havenā€™t done this yet, follow this guide.

2. Letā€™s say you have a SQL query pulling data from a table with a filter condition on the date column (e.g., created_at > ā€˜2023-10-01ā€™).
Original SQL query:

3. Instead of specifying the date in the query, you can put the desired date in any of your Google Sheets and reference that cell in your SQL query.

The cell references should be in the format ā€œ+++SHEET_NAME!CELL+++ā€. This informs Two Minute Reports that thereā€™s a cell reference in your SQL query.

For this example, letā€™s say your sheet name is ā€œOrders Reportā€ and your cell is ā€œB1ā€. For this, your cell reference will be in the format ā€œ+++ā€˜Order Reportā€˜!B1+++ā€.

Modified SQL Query:

Now, whenever the query runs, Two Minute Reports will fetch the date from cell ā€œB1ā€ in the ā€œOrders Reportā€ sheet and substitute the cell reference in your SQL query with that date.

Important Notes:

  1. Be sure to enclose the cell reference with +++ on both sides to signal Two Minute Reports that itā€™s a dynamic value.
  2. If your sheet name has spaces like ā€œOrders Reportā€, enclose it in single quotes (ā€˜).
  3. You canā€™t specify a range of cells, such as ā€œ+++ā€™Orders Reportā€™!A2:A5+++ā€.

By using this feature, you can dynamically adjust values in your SQL query, fetching specific rows with an ā€œactiveā€ status or changing the sorting column from ā€œcreated_atā€ to ā€œupdated_atā€.

We hope this feature and guide are helpful. If you have any more questions or need help, donā€™t hesitate to reach out by creating a support ticket here.

Tags: , , ,

Was this helpful?