> For the complete documentation index, see [llms.txt](https://docs-v3.toucantoco.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs-v3.toucantoco.com/tutorials/advanced-tutorials/advanced-syntax-for-sql-queries.md).

# Using advanced syntax for SQL queries

### SQL Query Interpolation Syntax

This page provides an overview of SQL interpolation techniques, focusing on how to dynamically inject parameterized values into SQL queries. It explains the differences between the `<%= %>` and `{{ }}` syntaxes for injecting frontend and backend variables, and offers practical examples for various data types and scenarios

#### Variable Injection Sources

* Frontend variables (set in app configuration or by requesters/filters):
  * Use `<%= %>` syntax
* Backend variables (from instance config or user attributes):
  * Use `{{ }}` syntax

#### String or Integer Values from User/Instance Context

For string attributes:

```sql
WHERE INDUSTRY = '\'{{ string_attribute }}\''
```

For numeric attributes:

```sql
WHERE INDUSTRY = '{{ numeric_attribute }}'
```

#### Checkbox Requester (Array) of Strings

Use "IN" instead of "=" and join syntax:

```sql
WHERE CATEGORY IN ('<%= requestersManager.requester_check.join("','") %>')
```

#### List of String Values from User Attributes/Instance Context

```sql
WHERE beer_kind IN ('{{ "\',\'".join(user.attributes.beer_kind) }}')
```

#### Array or List of Integers

For checkbox filter:

```sql
WHERE CATEGORY IN ('<%= requestersManager.requester_check.join(",") %>')
```

For user attributes:

```sql
WHERE beer_kind IN ('{{ ",".join(user.attributes.beer_kind) }}')
```

#### String Template Filtering

Based on user/instance context:

```sql
WHERE beer_kind LIKE '%{{ user.attributes.beer_kind }}%'
```

Based on requester value:

```sql
WHERE beer_kind LIKE '%<%= requestersManager.beerkind %>%'
```

#### List of String Templates from Checkbox Values

```sql
WHERE beer_kind LIKE '%<%=requestersManager.beerkind.length > 1 ?requestersManager.beerkind.join("%' OR beer_kind LIKE '%"):requestersManager.beerkind[0] %>%'
```

#### List of String Templates from User/Instance Context

```sql
WHERE beer_kind LIKE '%{{ ("%\' OR beer_kind LIKE \'%").join(user.attributes.beer_kind) if user.attributes.beer_kind|length > 0 else user.attributes.beer_kind[0] }}%'
```

This structure organizes the information into clear sections with appropriate headers, code blocks for SQL snippets, and consistent formatting.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs-v3.toucantoco.com/tutorials/advanced-tutorials/advanced-syntax-for-sql-queries.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
