---
title: Execute Query
description: Run SQL queries on connected data sources and optionally save results as files.
category: Data Operations
tags: [sql, query, execute, database, file output, encryption]
---

# Execute Query

## Description

The **Execute Query** activity allows users to execute SQL queries on files or data stored in a connected data source (e.g., database, storage, or file-based system).  
This activity supports dynamic queries, and optionally allows saving the results to files with encryption, formatting, and custom output configuration.

Use this activity to:

- Execute ad hoc or parameterized SQL queries on uploaded or connected data
- Retrieve transformed or filtered data for further processing
- Generate reports or structured data files from query results

> **Use Case**:  
> Useful in scenarios where data needs to be filtered, joined, aggregated, or reshaped before it’s used in reporting, validation, or export.

---

## Input

| Type  | Description                            |
| ----- | -------------------------------------- |
| Files | Files/data available in the connection |

---

## Output

| Type        | Format       | Description                                  |
| ----------- | ------------ | -------------------------------------------- |
| Data / File | Table / File | Query result as a table or downloadable file |

---

## Configuration Fields

| Field Name          | Required    | Description                                                                                     |
| ------------------- | ----------- | ----------------------------------------------------------------------------------------------- |
| **Connection**      | Yes         | Connection to the data source where the query should be executed.                               |
| **Query**           | Yes         | SQL query to be executed on the connected data source.                                          |
| **Save As File**    | No          | If enabled, the query result will be saved as a file.                                           |
| **Secret Key**      | Conditional | Encryption key used to secure the generated output file (enabled only if Save As File is true). |
| **File Pattern**    | Conditional | Pattern for naming the generated files.                                                         |
| **Sheet Name**      | Conditional | Sheet name to use in the generated file (for Excel formats).                                    |
| **File**            | Conditional | Template file to structure the output.                                                          |
| **Split by Column** | Conditional | Column name used to split the query result into multiple output files.                          |
| **Starting Row**    | Conditional | Row index in the template file from where data insertion begins.                                |
| **Starting Column** | Conditional | Column index in the template file from where data insertion begins.                             |

---

## Sample Input

_Not applicable_ — data is pulled from the connected data source.

---

## Sample Configuration

| Field           | Value                                           |
| --------------- | ----------------------------------------------- |
| Connection      | `AzureBlobConnection`                           |
| Query           | `SELECT * FROM SalesData WHERE Region = 'East'` |
| Save As File    | `true`                                          |
| Secret Key      | `Encrypt@123`                                   |
| File Pattern    | `Sales_Report_[Region]`                         |
| Sheet Name      | `EastRegionSales`                               |
| Split by Column | `Region`                                        |
| Starting Row    | `2`                                             |
| Starting Column | `B`                                             |

---

## Sample Output

| Customer | Product | Region | Amount |
| -------- | ------- | ------ | ------ |
| John     | Laptop  | East   | 1200   |
| Alice    | Printer | East   | 400    |

> If "Save As File" is enabled, this output will be saved in the specified file format.
