queryToFile Step

Use this feature to execute a SQL query and create a file from the SQL results.

Last published at: September 8th, 2026

Description:

The Query to File step runs a configured SQL query against a selected database connection and creates a file with the results.

The step provides options to:

  • Select the database connection.
  • Connect to a different database, if needed.
  • Enter a SQL query.
  • Select the result file format.
  • Store the generated file path in a Variable or Global variable.
  • Configure SQL parameters for the query. 

This step is useful when you need to extract workflow data from a database and make it available as a file for subsequent workflow activities.

 

Inputs

  • Connection string - Selects the database connection to use when executing the query.
  • Connect to a different database – Specifies a different database connection target when required.
  • Enter SQL query – Specifies the SQL query that produces the results for the output file.
  • Result file format – Specifies the format of the generated result file.
  • Variable/Global to hold file path - Specifies the Variable or Global that will hold the generated file path.
  • SQL parameters - Provides SQL parameter mappings for the query.
 

 

Returns

  • True – The successful path that can be connected to the next workflow activity after the query-to-file operation completes successfully.
  • False – The alternate path that can be used for error handling or an alternative workflow path if the operation does not complete as expected.
 

 

Usage:

The Query to File step typically comes after a workflow determines what data to extract from a database.

A typical workflow pattern is:

Prepare Query → Query to File → Use Generated File

The generated file path can then be used by later workflow steps for activities such as:

  • File processing.
  • File storage or movement.
  • Sending the generated file to another activity.
  • Preparing an attachment.
  • Providing database results as workflow output.
  • Performing additional processing on the exported data.

 

Typical Workflow Suggestions:

Export Database Results

Use the step to execute a query and create a file containing the resulting database information.

Example:

Prepare Query → Query to File → Process File

This is useful when subsequent workflow activities need to handle database results as a file.

 

Create a Scheduled Data Export

Use Query to File in a scheduled or recurring workflow to generate an export from database data.

Example:

Start → Query to File → Store/Send File

You can store the generated file path in a Variable or Global and pass it to subsequent activities.

 

Generate a Report File

Use a SQL query to retrieve the data required for a report and create a file from the results.

Example:

Retrieve Data → Query to File → Send Report

The selected Result file format determines the configured format of the generated result file.

 

Prepare a File for Email

Generate a database-results file and then use the resulting file path in a downstream email workflow.

Example:

Query to File → Use File Path → Send Email

The Variable/Global to hold the file path property is specifically provided to make the generated file path available to the workflow.

 

Export Data for Downstream Processing

Use Query to File when another workflow activity requires database results as a file.

Example:

Query to File → File Processing → Continue Workflow

The file path can be passed to the downstream activity through the configured Variable or Global.

 

Query a Different Database

Use the Connect to different database property when the workflow requires the query to target a different database.

Example:

Select Connection → Specify Database → Query to File

The XML exposes this as an optional string property, but it does not specify the exact format or how to interpret the value.

 

Use Parameterized SQL

Configure SQL parameters when the query requires parameter values.

Example:

Collect Input → Query to File → Process Results

The clsSQLParams property type is explicitly defined for mapping SQL parameters.

 

Create Integration Data

Use the step to create a file containing database results that can subsequently be passed to another system or integration process.

Example:

Retrieve Data → Query to File → External Integration

You can supply the generated file path to the downstream activity.

 

Store the Generated File Path for Reuse

Because the step explicitly provides a Variable/Global to hold the file path property, you can retain the generated path for multiple subsequent workflow activities.

Example:

Query to File → Store File Path → Multiple Subsequent Steps

This follows the reusable-result pattern demonstrated in the reference documentation.

 

Generate Multiple Output Files

A workflow can use multiple Query to File steps when it needs different queries or result files.

Example:

Query 1 → Query to File → Query 2 → Query to File → Process Files

Use separate Variables or Globals for the resulting file paths so that downstream activities can distinguish the generated files.

 

Example:

Let’s build and execute the “queryToFileDef” example.          

  • Create a new process definition called “queryToFileDef” and open it in Designer mode.
  • Drag a “queryToFile” step to the canvas. 
  • Connect the dots between the “Start” and “queryToFile” steps, as shown above. 
  • Select the line between the steps to configure the “Connection Properties”. The default property values are “None, True, False, Error, and Evaluate”. Depending on the step’s purpose, you can configure additional values.
  • Click the “queryToFile” step to configure its “Required” properties. Provide a name for the step. Select the connection string from the drop-down list. Enter an SQL SELECT query. Select the result type (CSV, Excel) from the drop-down list. Specify a variable or global to store the result. Click the Save button. Note: Click the "AI Predict" button to have Copilot add new process steps that match your process description. 

 

  • Click the “queryToFile” step to configure its “Optional” properties. If needed, specify a different database name available with the same connection parameters. By default, the step connects to the FlowWright database, and a different database takes precedence when configured.  

 

  • The “Logging” configuration is necessary for documentation and also measures workflow progress and percent complete. This is achieved by configuring the step state and percent fields individually, as shown in the images below. Configure the “Logging” using the following properties.

 

  • Save the process definition, create a new instance, and execute it. Render the process instance and click the Query to File step to view its properties. When the workflow reaches the Query to File step, FlowWright uses the configured database connection and SQL query to perform the operation and creates the result file according to the configured result file format. The resulting file path is held in the configured Variable or Global and can then be used by subsequent workflow activities.

 

  • Render the process instance. Inspect the step variable or properties. Inspect the output result file. The column headers in the output Excel file match the columns specified in the SQL query, respecting Pascal-style casing.  

 

Tips:

  • Use a meaningful name for the Variable or Global that stores the generated file path.
  • Use a clearly defined database connection appropriate for the workflow.
  • Verify that the selected connection has access to the required database and data.
  • Keep SQL queries readable, particularly when using multiline queries.
  • Test the SQL query independently before incorporating it into a workflow.
  • Use SQL parameters when the query requires runtime values rather than embedding changing values directly into the SQL statement.
  • Keep SQL parameter names and their corresponding query references consistent.
  • Select a result file format appropriate for the activity that will consume the generated file.
  • Test the generated file with realistic result data.
  • Verify that downstream workflow activities use the Variable or Global containing the generated file path.
  • Use separate destination Variables or Globals when multiple Query to File steps create different files.
  • Test both the True and False paths.
  • Avoid exposing database credentials or other sensitive connection information in documentation or workflow examples.
  • Use appropriate database permissions for the workflow's connection.
  • Consider the size of the query result when designing workflows that generate files.
  • If using Connect to a different database, verify the expected value and behavior in the target environment.
  • The XML does not specify how SQL errors, empty result sets, invalid connections, file-generation errors, or parameter errors are handled, so test these conditions rather than assume they work.

 

Notes:

  • Category: Database
  • Internal Name: querytofile
  • Label: Create file from SQL results
  • Display Name: Query to file
  • Namespace: FlowWright.Workflow.QueryToFile
  • DLL: FlowWright.Workflow.dll
  • Step Definition Type: Process
  • Incoming Connections: 2
  • Outgoing Connections: 2

 

Definition Sample:

A sample Query to File definition demonstrates retrieving database data and creating a file that a subsequent workflow activity consumes.

Before importing or using a definition sample, verify:

  • The Connection string points to the intended database connection.
  • The SQL query is appropriate for the target database.
  • Any required SQL parameters are correctly mapped.
  • If used, the connection to a different database is configured correctly.
  • The selected Result file format is supported by the intended downstream process.
  • The Variable/Global to hold the file path is correctly defined.
  • Downstream activities reference the correct file-path Variable or Global.
  • The database connection has the permissions required by the query.
  • The True and False paths are connected appropriately.
  • Sensitive connection and database information is not exposed in sample documentation.

Save the process definition before creating and executing a workflow instance.

Click here to download the sample file.