> ## Documentation Index
> Fetch the complete documentation index at: https://docs.allium.so/llms.txt
> Use this file to discover all available pages before exploring further.

# Create a parameterized query

> Build reusable queries with configurable parameters for flexible data analysis.

Parameterized queries allow you to create reusable SQL templates with configurable values. Instead of writing multiple similar queries, you can define parameters that can be changed each time you run the query.

## How to Use Parameters

Replace any value in your query with `{{param_name}}` to create a parameter. The query editor will automatically detect these parameters and provide input fields for them.

<Steps>
  <Step title="Write a Query with Parameters">
    Use double curly braces to define parameters in your SQL query:

    ```sql theme={null}
    -- DEX USD volume for a configurable chain and time period
    select
      date(block_timestamp) as date,
      chain,
      sum(usd_amount) as usd_volume
    from crosschain.dex.trades
    where
      block_timestamp >= current_timestamp - interval '{{last_n_days}} days'
      and chain = '{{chain}}'
    group by all
    order by date asc;
    ```
  </Step>

  <Step title="Set Parameter Values">
    The query editor automatically detects parameters and displays input fields. Enter your desired values:

    * **last\_n\_days**: `3`
    * **chain**: `solana`

    <Frame>
      <img src="https://mintcdn.com/allium-e770e2b7/ZJULWDhWUB9qEr_O/images/run-query-parameterized.png?fit=max&auto=format&n=ZJULWDhWUB9qEr_O&q=85&s=fbe34bb4c8f6364542e9beb8b5580b37" alt="Query with parameters" width="2012" height="726" data-path="images/run-query-parameterized.png" />
    </Frame>
  </Step>

  <Step title="Run and Iterate">
    Click **Run** to execute the query with your parameter values. You can modify the parameters and re-run the query to analyze different chains, time periods, or other variables without rewriting the SQL.
  </Step>
</Steps>

## Advanced Parameter Techniques

<Tabs>
  <Tab title="API Integration">
    Parameters become even more powerful when using the [Explorer API](/api/explorer/overview) to run queries programmatically. You can dynamically set parameter values in your API requests to create flexible data pipelines and applications.

    This enables:

    * Automated data pulls with variable filters
    * User-driven dashboards and reports
    * Dynamic data exports based on business logic
  </Tab>

  <Tab title="Dynamic SQL">
    **Power User Tip:** You can parameterize an entire SQL query by using `{{sql}}` as the query text:

    ```sql theme={null}
    {{sql}}
    ```

    When calling the API, provide the complete SQL as the parameter value. This enables dynamic query generation and execution without modifying the saved query.

    **Use cases:**

    * Applications that generate queries based on user input
    * A/B testing different query approaches without the Allium App interface
    * Programmatically building complex queries with conditional logic
  </Tab>
</Tabs>

## Next Steps

<CardGroup cols={2}>
  <Card title="Basic Queries" href="/app/run-queries/basic-query">
    Learn the fundamentals of running queries
  </Card>

  <Card title="Query Previous Results" href="/app/run-queries/query-on-previous-result">
    Build on top of completed query runs
  </Card>

  <Card title="Explorer API" href="/api/explorer/overview">
    Execute parameterized queries programmatically
  </Card>

  <Card title="Visualize Results" href="/app/visualisations">
    Create charts and visualizations from query results
  </Card>
</CardGroup>
