This activity executes SQL statements within SharePoint Designer workflows and returns the result back to the workflow.
Note: The default provider is MS SQL Server (System.Data.SqlClient). You can use other providers like ODBC, Oracle, etc.
This activity supports multiple batches separated by the GO
command. GO
is not a Transact-SQL statement; it is a command recognized by this activity. The activity interprets GO
as a signal to send the current batch of Transact-SQL statements to an instance of SQL Server. The current batch of statements includes all statements entered since the last GO
, or since the start of the session if it is the first GO
. A Transact-SQL statement cannot occupy the same line as a GO
command, though the line can contain comments.
To return a result from the SQL script to the workflow, you should assign the output to the output variable.
Working with Parameter Placeholders
The syntax for parameter placeholders depends on the data provider. The .NET Framework data providers handle naming and specifying parameters and parameter placeholders differently, with syntax customized for each data provider. The syntax for common data providers is described in the table below:
Data provider | Parameter naming syntax |
System.Data.SqlClient | Uses output parameters in the format @output_result . |
System.Data.OleDb | Uses positional parameter markers indicated by a question mark ? . |
System.Data.Odbc | Uses positional parameter markers indicated by a question mark ? . |
System.Data.OracleClient | Uses output parameters in the format :output_result (or output_result ). |
Example: Sql script for System.Data.SqlClient provider
GO
DECLARE @var1 VARCHAR(10);
SET @var1 = 'sample';
SET @output_result = @var1;
GO
Example: Sql script for System.Data.OleDb provider
GO
DECLARE @var1 VARCHAR(10);
SET @var1 = 'test';
SET ? = @var1;
GO
SharePoint Workflow Designer Phrase
Execute SQL Script this SQL script using this provider name, this connection string, and store result in Variable
Parameters
Parameter | Description |
this SQL script | SQL statements. Supports multiple batches separated by the GO command. |
this provider name | The .NET ADO Provider. Default is MS SQL Server (System.Data.SqlClient ). You can also use:– System.Data.Odbc – ODBC Data Provider– System.Data.OleDb – OleDb Data Provider– System.Data.OracleClient – OracleClient Data Provider– System.Data.SqlServerCe.3.5 – Microsoft SQL Server Compact Data ProviderFor more information about providers, see here. |
this connection string | The connection string, e.g., Data Source=localhost\SQLExpress;Initial Catalog=test;Integrated Security=SSPI . |
Variable | Gets or sets the output result. |