Stored Procedure Action

Description

Executes the selected stored procedure via OLEDB on the data source specified. Stored procedures are configured on the database server and are often faster than repeated SQL calls. Useful for Automated Workflow retrieval, update, or transfer of data. Could also be used to test database response times and size quotas.

IMPORTANT: Because the results retrieved may contain multiple records (think of records as rows) and multiple fields (think columns) - to access data retrieved from SQL Query you must use the Loop Dataset Action <AMLOOPDATASET> to iterate the records and embedded expressions to extract the data from the individual fields (e.g. %datasetname.fieldname% ). It sounds more difficult than it actually is - see notes below for more information.

Declaration

<AMSQLQUERY CONNECTIONSTRING="text" RESULTDATASET="text" SQLSTATEMENT="text" MAXROWS="number" LOGIN="yes/time" TIMEOUT="number" CACHEDAFTER="datetime">

Example

<AMSQLSTOREDPROC CONNECTIONSTRING="Provider=SQLOLEDB.1;Password=password;Persist Security Info=True;User ID=username;Initial Catalog=Testing;Data Source=server" PROCEDURE="sp_delete_activity" NAMES="RETURN_VALUE,@activityid" VARIABLES="&quot;&quot;,&quot;&quot;" TYPES="Integer,WideString" DIRECTIONS="ReturnValue,Input" PRECISIONS="10,0" NUMSCALES="0,0" SIZES="0,15" ATTRIBUTES="&quot;&quot;,Null">

General Tab Parameters

Connection string type: Specify to Use custom connection string, Use existing SQL connection from a session, Use pre-defined connection string. Generate a connection string is by clicking the New icon .

Connection String: Specifies an OLEDB connection string. The connection string provides driver, server, username, password and other important information to the OLEDB subsystem so that the connection can be made. The easiest way to generate a proper connection string is by clicking New on the visual step editor. The connection string is automatically encrypted when adding the step in Visual Mode.

Text, Required
MARKUP:
a) CONNECTIONSTRING="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Program Files\Common Files\Borland Shared\Data\BCDEMOS.mdb"

Stored Procedure: Name of the dataset that should be created and populated with the results (if any) of the SQL Statement upon execution. To access the data in subsequent steps simply specify %DATASETNAME.FIELDNAME% inside a Loop Dataset <AMLOOPDATASET> action (to recurse the rows).

Text, Required
MARKUP: PROCEDURE="sp_delete_activity"

Prompt User for Name and Password: Specifies that the user should be prompted with a username and password for the database server each time the Workflow is run.

Yes/No, Optional - Default - NO
MARKUP: LOGIN="YES"

Advanced Tab Parameters

Time Out After: Specifies the amount of seconds that the query should be allowed before timing out at the server level.

Number, Optional Default - 0
MARKUP: TIMEOUT="500"

Create and Populate Dataset: Name of the dataset that should be created and populated with the results (if any) of the SQL Statement upon execution. To access the data in subsequent steps simply specify %DATASETNAME.FIELDNAME% inside a Loop Dataset <AMLOOPDATASET> action (to recurse the rows).

Text, Required
MARKUP: RESULTDATASET="DATESETNAME"

Notes

A variable field Dataset is generated. A dataset is a multiple column, multiple row container object. This action creates and populates a dataset, the fields contained within that dataset are determined by the query that was executed. For example, if a stored procedure containing the following query is executed:

SELECT firstname, lastname, company from customer where city='Los Angeles';

Then the following data set would be generated:

datasetname
|--firstname
|--lastname
|--company

along with the standard fields included in every dataset

|--CurrentRow
|--TotalRows
|--TotalColumns
|--ExecutionDate
|--RowsAffected
|--SQLQuery
|--Datasource

A record (row) is created for each record (row) that is retrieved from the server. To access this data use the Loop Dataset Action <AMLOOPDATASET> to loop through the records, inside the loop you can extract the data from the field of your choice (from the current record) by using an embedded expression such as the one that follows:

%mydatasetname.firstname%

or you could combine two fields together like this:

%mydatasetname.firstname + " " + mydatasetname.lastname%

Embedded Expressions such as these can be used in any parameter in any action. So, to display the data in a message box the AML code would look like this:

 <AMMESSAGEBOX MESSAGETEXT="%mydatasetname.firstname%" WINDOWTITLE="The firstname of the current record is">

At runtime, the text %mydatasetname.firstname% is replaced by the contents of the subject of the current record.

See Also

Loop Dataset, Open SQL Connection Action, Close SQL Connection Action, Execute SQL Query Action