Microsoft Flow Execute Sql Query

Nov 26, 2018  Hi, I am trying to use the Execute a SQL Query as shown below: The flow fails with a message How can I get the query to run? Hi, I am trying to use the Execute a SQL Query as shown below: The flow fails with a message How can I get the query to run? Microsoft Flow Community Manager Report Inappropriate Content. Message 5 of 7 Everyone's. We have recently shipped, in public preview, Power Query Online integration for Microsoft Flow. Using this capability allows flow makers to transform and shape their data coming from SQL Server using Power Query Online. On a daily basis, execute a SQL query, store the results in an SFTP server in a CSV format and send an email providing details. It's free to get started. Sign up with your email.

-->

This topic describes how to use a parameterized SQL statement in the Execute SQL task and create mappings between variables and the parameters in the SQL statement.

To learn more about the Execute SQL task, the parameter markers, and parameter names you use with different connection types, see Execute SQL Task and Parameters and Return Codes in the Execute SQL Task.

To map a query parameter to a variable

  1. In SQL Server Data Tools (SSDT), open the Integration Services package you want to work with.

  2. In Solution Explorer, double-click the package to open it.

  3. Click the Control Flow tab.

  4. If the package does not already include an Execute SQL task, add one to the control flow of the package. For more information, see Add or Delete a Task or a Container in a Control Flow
    .

  5. Double-click the Execute SQL task.

  6. Provide a parameterized SQL command in one of the following ways:

    • Use direct input and type the SQL command in the SQLStatement property.

    • Use direct input, click Build Query, and then create an SQL command using the graphical tools that the Query Builder provides.

    • Use a file connection and then reference the file that contains the SQL command.

    • Use a variable and then reference the variable that contains the SQL command.

    The parameter markers that you use in parameterized SQL statements depend on the connection type that the Execute SQL task uses.

    Connection typeParameter marker
    ADO?
    ADO.NET and SQLMOBILE@<parameter name>
    ODBC?
    EXCEL and OLE DB?

    The following table lists examples of the SELECT command by connection manager type. Parameters provide the filter values in the WHERE clauses. The examples use SELECT to return products from the Product table in AdventureWorks2012 that have a ProductID greater than and less than the values specified by two parameters.

    Connection typeSELECT syntax
    EXCEL, ODBC, and OLEDBSELECT* FROM Production.Product WHERE ProductId > ? AND ProductID < ?
    ADOSELECT* FROM Production.Product WHERE ProductId > ? AND ProductID < ?
    ADO.NETSELECT* FROM Production.Product WHERE ProductId > @parmMinProductID AND ProductID < @parmMaxProductID

    For examples of using parameters with stored procedures, see Parameters and Return Codes in the Execute SQL Task.

  7. Click Parameter Mapping.

  8. To add a parameter mapping, click Add.

  9. Provide a name in the Parameter Name box.

    The parameter names that you use depend on the connection type that the Execute SQL task uses.

    Connection typeParameter name
    ADOParam1, Param2, ...
    ADO.NET and SQLMOBILE@<parameter name>
    ODBC1, 2, 3, ...
    EXCEL and OLE DB0, 1, 2, 3, ...
  10. From the Variable Name list, select a variable. For more information, see Add, Delete, Change Scope of User-Defined Variable in a Package.

  11. In the Direction list, specify if the parameter is an input, an output, or a return value.

  12. In the Data Type list, set the data type of the parameter.

    Important

    The data type of the parameter must be compatible with the data type of the variable.

  13. Repeat steps 8 through 11 for each parameter in the SQL statement.

    Important

    The order of parameter mappings must be the same as the order in which the parameters appear in the SQL statement.

  14. Click OK.

See Also

Powerapps Execute Sql Query

Execute SQL Task
Parameters and Return Codes in the Execute SQL Task
Integration Services (SSIS) Variables

-->

Microsoft SQL Server is a relational database management system developed by Microsoft. Connect to SQL Server to manage data. You can perform various actions such as create, update, get, and delete on rows in a table.

This connector is available in the following products and regions:

ServiceClassRegions
Logic AppsStandardAll Logic Apps regions
FlowStandardAll Flow regions
PowerAppsStandardAll PowerApps regions

To use this connector in PowerApps, learn more here.

Known issues and limitations

The followings are some of the known limitations of using SQL connector

  1. Stored Procedures cannot be invoked from PowerApps.
    • One workaround is to create a Flow and invoke the Flow from PowerApps.
  2. Insert and update to a table does not work if you have a SQL server side Trigger defined on the table. To workaround this issue, you can do either of the following:
    • Use a Stored Procedure or Native Query
    • Remove the Trigger from your SQL table
  3. When invoking a Stored Procedure on an on-premises SQL server, we have the following limitations:
    • Output values for OUTPUT parameters are not returned. You can still specify input values for OUTPUT parameters.
    • Return value is not available.
    • Only the first result set is returned.
    • Dynamics schemas are not supported for result sets.
  4. A Primary Key is required for the following operations:
    • GetItem
    • UpdateItem
    • DeleteItem
  5. When invoking triggers, we have the following limitations:
    • A ROWVERSION column is required for OnUpdatedItems
    • An IDENTITY column is required for OnNewItems
  6. The response size limit is 8MB through on-premises SQL server.
  7. The request size limit is 2MB through on-premises SQL server.
  8. SQL native query is not supported for on-premises SQL server.
  9. The following data types cannot be used as query option predicates:
    • date
    • datetime
    • datetime2
    • smalldatetime
  10. The result set schema after executing SQL queries and stored procedures should contain unique non-empty column names.
  11. The result set schema for any operation inside the stored procedure that returns some set of results (e.g. any inner SELECT statement) should contain unique non-empty column names.

PowerApps data type mappings

SQL ServerPowerApps
bigint, decimal, int, money, numeric, smallint, smallmoney, tinyint, float, realNumber
char, nchar, varchar, nvarchar, text, ntextText
bitBoolean
date, datetime/datetime2/smalldatetime, datetimeoffset, timeDateTime
uniqueidentifierGuid

Note

If a SQL Server data type is not listed in the table above, it is not supported. Examples of unsupported SQL Server data types include: binary(), varbinary(), image, cursor, rowversion, hierarchyid, sql_variant xml, Spatial Geometry Types, Spatial Geography Types, and table.

PowerApps delegable functions and operations for SQL Server

These PowerApps operations, for a given data type, may be delegated to SQL Server for processing (rather than processing locally within PowerApps).

Operation/FunctionNumberTextBooleanDateTimeGuid
FilterYesYesYesNo [1]Yes
SortYesYesYesYes-
SortByColumnsYesYesYesYes-
SearchNoYesNoNo-
LookupYesYesYesYesYes
=, <>YesYesYesNoYes
<, <=, >, >=YesNoNoNo-
in (substring)-Yes [2]---
+Yes--No-
-Yes--No-
*Yes--No-
/Yes--No-
StartsWith-Yes [3]---
EndsWith-Yes [4]---
IsBlankNo [5]No [5]No [5]No [5]No [5]
Len (length)-Yes [6]---
SumYes----
AverageYes----
MinYes--No-
MaxYes--No-

Note

Expressions joined with And, Or, and Not are delegable to SQL Server.

  1. Direct date filters do not work for SQL Server. However, you can create a calculated column that will work. For instance, ALTER TABLE myTable ADD DateAsInt AS (YEAR([date]) * 10000 + MONTH([date]) * 100 + DAY([date])) and then filter on the calculated number column.
  2. The 'in' (substring) operator. Supported for ('string value' in <column>), but not for (<column> in 'string value').
  3. StartsWith. Supported for (StartsWith(<column>, 'string value')), but not for (StartsWith('string value', <column>)).
  4. EndsWith. Supported for (EndsWith(<column>, 'string value')) but not for (EndsWith('string value', <column>)). If a char(10) column has a value of 'hello', EndsWith(<column>, 'llo') will return false, and that's by design. A char(10) column has 10 characters.
  5. An expression such as Filter('[dbo].[MyOrders]', !IsBlank(CustomerId)) won't delegate to the server. However, this is semantically close to Filter('[dbo].[MyOrders]', CustomerId <> Blank()), which does delegate to the server. These expressions differ in that the second expression won't treat the empty string (') as Empty. These expressions aren't equivalent, but the latter might work for your purposes. You can’t use this method for the Guid data type.
  6. Len. PowerApps delegates the Len function, but it might not work as you expect. A char(10) column with value 'hello' will always have, in SQL Server, a length of 10. But PowerApps will treat that string as having a length of 5, which could cause discrepancies and confusion. You shouldn't use char/nchar on the server; use varchar/nvarchar instead.

Creating a connection

To connect your account, you will need the following information:

NameTypeDescription
SQL server name string

SQL server name

SQL database name string

SQL database name

Authentication Type string

Authentication type to connect to your database

Username securestring

Username credential

Password securestring

Password credential

Gateway gatewaySetting

Throttling Limits

NameCallsRenewal Period
API calls per connection10010 seconds

Actions

Delete row (V2)

This operation deletes a row from a table.

Delete row [DEPRECATED]

This operation deletes a row from a table.

Execute a SQL query (V2)

Execute a SQL query (V2)

Execute a SQL query [DEPRECATED]

Execute a SQL query

Execute stored procedure (V2)

This operation runs a stored procedure.

Execute stored procedure [DEPRECATED]

This operation runs a stored procedure.

Get row (V2)

This operation gets a row from a table.

Get row [DEPRECATED]

This operation gets a row from a table.

Get rows (V2)

This operation gets rows from a table.

Get rows [DEPRECATED]

This operation gets rows from a table.

Get tables (V2)

This operation gets tables from a database.

Get tables [DEPRECATED]

This operation gets tables from a database.

Insert row (V2)

This operation inserts a new row into a table.

Insert row [DEPRECATED]

This operation inserts a new row into a table.

Transform data using Power Query

Transform data using Power Query

Update row (V2)

This operation updates an existing row in a table.

Update row [DEPRECATED]

This operation updates an existing row in a table.

Delete row (V2)

This operation deletes a row from a table.

Parameters

NameKeyRequiredTypeDescription
server True string

Name of SQL server

Database name
database True string

Database name

table True string

Name of table

Row id
id True string

Unique identifier of the row to delete

Delete row [DEPRECATED]

This operation deletes a row from a table.

Parameters

NameKeyRequiredTypeDescription
table True string

Name of table

Row id
id True string

Unique identifier of the row to delete

Execute a SQL query (V2)

Execute a SQL query (V2)

Parameters

NameKeyRequiredTypeDescription
server True string

Name of SQL server

Database name
database True string

Database name

query True dynamic

query body

Returns

The outputs of this operation are dynamic.

Execute a SQL query [DEPRECATED]

Execute a SQL query

Parameters

NameKeyRequiredTypeDescription
query True dynamic

query body

Returns

The outputs of this operation are dynamic.

Execute stored procedure (V2)

This operation runs a stored procedure.

Parameters

NameKeyRequiredTypeDescription
server True string

Name of SQL server

Database name
database True string

Database name

procedure True string

Name of stored procedure

Parameters list
parameters True dynamic

Input parameters to the stored procedure

Returns

Execute stored procedure [DEPRECATED]

This operation runs a stored procedure.

Parameters

NameKeyRequiredTypeDescription
procedure True string

Name of stored procedure

Parameters list
parameters True dynamic

Input parameters to the stored procedure

Returns

Get row (V2)

This operation gets a row from a table.

Parameters

NameKeyRequiredTypeDescription
server True string

Name of SQL server

Database name
database True string

Database name

table True string

Name of SQL table

Row id
id True string

Unique identifier of the row to retrieve

Returns

Get row [DEPRECATED]

This operation gets a row from a table.

Parameters

NameKeyRequiredTypeDescription
table True string

Name of SQL table

Row id
id True string

Unique identifier of the row to retrieve

Returns

Get rows (V2)

This operation gets rows from a table.

Parameters

NameKeyRequiredTypeDescription
server True string

Name of SQL server

Database name
database True string

Database name

table True string

Name of SQL table

Aggregation transformation
$apply string

A sequence of OData aggregation transformations

$filter string

An ODATA filter query to restrict the entries returned (e.g. stringColumn eq 'string' OR numberColumn lt 123).

Order By
$orderby string

An ODATA orderBy query for specifying the order of entries.

$skip integer

The number of entries to skip (default = 0).

Top Count
$top integer

Total number of entries to retrieve (default = all).

$select string

Specific fields to retrieve from entries (default = all).

Returns

The outputs of this operation are dynamic.

Get rows [DEPRECATED]

This operation gets rows from a table.

Parameters

NameKeyRequiredTypeDescription
table True string

Name of SQL table

Aggregation transformation
$apply string

A sequence of OData aggregation transformations

$filter string

An ODATA filter query to restrict the entries returned (e.g. stringColumn eq 'string' OR numberColumn lt 123).

Order By
$orderby string

An ODATA orderBy query for specifying the order of entries.

$skip integer

The number of entries to skip (default = 0).

Top Count
$top integer

Total number of entries to retrieve (default = all).

$select string

Specific fields to retrieve from entries (default = all).

Returns

The outputs of this operation are dynamic.

Get tables (V2)

This operation gets tables from a database.

Parameters

NameKeyRequiredTypeDescription
server True string

Name of SQL server

Database name
database True string

Database name

Returns

Represents a list of tables.

Get tables [DEPRECATED]

This operation gets tables from a database.

Returns

Represents a list of tables.

Insert row (V2)

This operation inserts a new row into a table.

Parameters

NameKeyRequiredTypeDescription
server True string

Name of SQL server

Database name
database True string

Database name

table True string

Name of table

Row
item True dynamic

Row to insert into the specified table

Returns

Insert row [DEPRECATED]

This operation inserts a new row into a table.

Parameters

NameKeyRequiredTypeDescription
table True string

Name of table

Row
item True dynamic

Row to insert into the specified table

Returns

Transform data using Power Query

Transform data using Power Query

Parameters

NameKeyRequiredTypeDescription
query mquery

Query Text

Returns

The outputs of this operation are dynamic.

Update row (V2)

This operation updates an existing row in a table.

Parameters

NameKeyRequiredTypeDescription
server True string

Name of SQL server

Database name
database True string

Database name

table True string

Name of table

Row id
id True string

Unique identifier of the row to update

item True dynamic

Row with updated values

Returns

The outputs of this operation are dynamic.

Update row [DEPRECATED]

This operation updates an existing row in a table.

Parameters

NameKeyRequiredTypeDescription
table True string

Name of table

Row id
id True string

Unique identifier of the row to update

item True dynamic

Row with updated values

Returns

The outputs of this operation are dynamic.

Triggers

When an item is created (V2)

Triggers a flow when an item is created in Sql

When an item is created [DEPRECATED]

Triggers a flow when an item is created in Sql

When an item is modified (V2)

Triggers a flow when an item is modified in Sql

When an item is modified [DEPRECATED]

Triggers a flow when an item is modified in Sql

Query

When an item is created (V2)

Triggers a flow when an item is created in Sql

Parameters

NameKeyRequiredTypeDescription
server True string

Name of SQL server

Database name
database True string

Database name

table True string

Name of Sql table

Filter Query
$filter string

An ODATA filter query to restrict the entries returned (e.g. stringColumn eq 'string' OR numberColumn lt 123).

$top integer

Total number of entries to retrieve (default = all).

Order By
$orderby string

An ODATA orderBy query for specifying the order of entries.

$select string

Specific fields to retrieve from entries (default = all).

Returns

The outputs of this operation are dynamic.

When an item is created [DEPRECATED]

Triggers a flow when an item is created in Sql

Parameters

NameKeyRequiredTypeDescription
table True string

Name of Sql table

Filter Query
$filter string

An ODATA filter query to restrict the entries returned (e.g. stringColumn eq 'string' OR numberColumn lt 123).

$top integer

Total number of entries to retrieve (default = all).

Order By
$orderby string

An ODATA orderBy query for specifying the order of entries.

$select string

Specific fields to retrieve from entries (default = all).

Returns

The outputs of this operation are dynamic.

When an item is modified (V2)

Triggers a flow when an item is modified in Sql

Microsoft Flow Execute Sql Query In Java

Parameters

NameKeyRequiredTypeDescription
server True string

Name of SQL server

Database name
database True string

Database name

table True string

Name of Sql table

Filter Query
$filter string

An ODATA filter query to restrict the entries returned (e.g. stringColumn eq 'string' OR numberColumn lt 123).

$top integer

Total number of entries to retrieve (default = all).

Order By
$orderby string

An ODATA orderBy query for specifying the order of entries.

$select string

Specific fields to retrieve from entries (default = all).

Microsoft Flow Execute Sql Query In Jdbc

Returns

The outputs of this operation are dynamic.

When an item is modified [DEPRECATED]

Triggers a flow when an item is modified in Sql

Microsoft Flow Update Sql Table

Parameters

NameKeyRequiredTypeDescription
table True string

Name of Sql table

Filter Query
$filter string

An ODATA filter query to restrict the entries returned (e.g. stringColumn eq 'string' OR numberColumn lt 123).

$top integer

Total number of entries to retrieve (default = all).

Order By
$orderby string

An ODATA orderBy query for specifying the order of entries.

$select string

Specific fields to retrieve from entries (default = all).

Returns

The outputs of this operation are dynamic.

Microsoft Flow Execute Sql Query Tutorial

Definitions

TablesList

Represents a list of tables.

NamePathTypeDescription
value array of Table

List of Tables

Table

Represents a table.

NamePathTypeDescription
Name string

The name of the table. The name is used at runtime.

DisplayName
DisplayName string

The display name of the table.

DynamicProperties object

Additional table properties provided by the connector to the clients.