Using the Export to data table action in the Database package - Use the Export to data table action in Automation 360 Database package to run a SELECT query and store the results directly in an in-memory table variable.

Automation 360

Use the Export to data table action in Automation 360 Database package to run a SELECT query and store the results directly in an in-memory table variable.

Unlike the Read from action, Export to data table action does not write the retrieved data to a CSV file. Instead, it loads the results into a table variable that you can use immediately in subsequent bot actions.

This action is useful when you need to:

  • Retrieve database records and process them row by row using a Loop action without creating an intermediate file.
  • Query a database and pass the results to Data Table package actions such as Sort, Search for a value, or Remove duplicate rows.
  • Export query results to a table variable for in-bot comparison, filtering, or transformation before writing to a file.
  • Retrieve records from Snowflake using an ODBC driver connection.
Note:
  • Export to data table action stores query results in memory as a table variable. The data is available only during the bot execution and is not persisted to a file unless you explicitly use the Write to file or Read from action afterwards.
  • If the selected table variable already contains data from a previous query, the Export to data table action overwrites the existing values. If you use this action twice in the same bot with different SELECT queries, the second call replaces the table contents from the first.
  • CTE (Common Table Expression) is supported using the WITH keyword in SQL-compliant databases such as Oracle and MySQL.
  • This action is supported across most major database types. See Database server support matrix for the full list.
  • The Snowflake database using the ODBC driver is supported.
  • This action does not support Microsoft Access or SQLite when exporting to a data table via ODBC. See Database server support matrix.

Prerequisites

Before using the Export to data table action, ensure the following:

  • A database session has been established using the Connect action. See Using Connect action for database.
  • You have a valid SELECT statement ready. The action does not support INSERT, UPDATE, or DELETE statements.

Settings

  • In the Enter SELECT Statement field, enter a valid SQL SELECT statement to specify the columns and table you want to query.

    This field supports standard SQL syntax. For example: SELECT CustomerName, City FROM Customers

    To filter results: SELECT CustomerName, City FROM Customers WHERE Country = 'USA'

    Note: CTE support: Common Table Expressions are supported in SQL-compliant databases such as Oracle and MySQL using the WITH keyword. For example:
    WITH customers_in_usa AS (
      SELECT CustomerName, State FROM Customers WHERE Country = 'USA'
    )
    SELECT CustomerName FROM customers_in_usa
    WHERE State = 'LA'
    ORDER BY CustomerName
  • In the Maximum number of records to fetch field, enter the maximum number of rows you want the query to return. If you leave this field blank, the action retrieves all records that match the query.
  • In the Timeout for the query in seconds field, enter the maximum number of seconds the query is allowed to run.

    If the query does not complete within the specified time, execution stops and the bot encounters an error. If you leave this field blank, the action waits until the query completes or the database driver's default timeout is reached.

  • In the Session name field, enter the name of the session you used in the Connect action.
  • In the Assigned to field, select the table variable where you want to store the query results. If no table variable exists, click the Create variable icon to create one.
    Note: If the selected table variable already contains data from a previous query or action, the Export to data table action overwrites those values entirely. To preserve earlier results, save them to a file first using the Write to file action, or assign them to a separate table variable before running this action.
  • Click Save. When the bot runs, the query executes and the results are stored in the selected table variable.

Example

In this example, you retrieve all Sales department records from a customer_records database table and store them in a table variable for further processing.

Prerequisites:

  • A database session named Default has been established using the Connect action.
  • A table variable called SalesResults has been created.
  • The customer_records table contains the following data:
cust_id cust_name department baseSalary
E1001 Mike Williams Sales 1200000
E1002 John Smith Finance 950000
E1003 Tom Jones HR 700000
E1004 Jack Sheryl Sales 1500000
E1005 Shawn George Operations 650000

Steps:

  1. Drag or double-click Export to data table action under the Database package.
  2. In the Enter SELECT Statement field, enter:
    SELECT cust_id, cust_name, department
    FROM customer_records
    WHERE department = 'Sales'
    ORDER BY cust_id
    
  3. Leave the Maximum number of records to fetch field blank to retrieve all matching records.
  4. Enter 120 in the Timeout for the query in seconds field.
  5. In Session name, enter Default.
  6. In Assigned to, select the table variable SalesResults.
  7. Click Save.

Result: When the bot runs, SalesResults contains the following data:

cust_id cust_name department
E1001 Mike Williams Sales
E1004 Jack Sheryl Sales

You can now use the SalesResults table variable directly in a Loop action to iterate through each record, or pass it to a Data Table package action for further processing.