# 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: Querying This Documentation

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

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

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

The question should be specific, self-contained, and written in natural language.
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.
