Azure SQL - Stored Procedure
On this Page
Snap type: | Write | ||||||
---|---|---|---|---|---|---|---|
Description: | This Snap invokes a stored procedure in the Azure SQL Database. If the procedure contains any OUT parameters, they are written to the output view. ETL Transformations & Data FlowThis Snap enables the following ETL operations/flows: Ideally, there is no data flow from the Snap to the database, however, the results computed in the store procedure or the result of queries executed in the stored procedure can be fetched by the Snap through output parameters. Input & Output
| ||||||
Prerequisites: | The SP to be invoked must be created before executing the Snap. | ||||||
Limitations and Known Issues: |
| ||||||
Configurations: | Account & AccessThis Snap uses account references created on the Accounts page of SnapLogic Manager to handle access to this endpoint. See Azure SQL Account for information on setting up this type of account. Views
| ||||||
Troubleshooting: | Ensure the input provided (Schema name and SP name) is correct. Ensure the input parameters are provided correctly. | ||||||
Settings | |||||||
Label | Required. The name for the Snap. You can modify this to be more specific, especially if you have more than one of the same Snap in your pipeline. | ||||||
Schema Name | The schema name where the procedure resides. The property is suggestible and will return all schemas of the DB. The values can be passed using the pipeline parameters but not the upstream parameter. Example: dbo | ||||||
Stored Procedure Name | Required. Stored procedure to execute. The property is suggestible and will return all procedures of the DB. If a package is defined, then it will only return the procedures of that package. If a schema is defined and no package is defined, then it will return all procedures of that schema. Example: addSeventeen | ||||||
Parameter Values | Select the input parameter values for the stored procedure. If you define parameter values, you must do so in the same order as they appear in the stored procedure definition. Example: Suppose there is a stored procedure named createGreeting. It has three parameters p1,p2, and p3. p1 and p2 are input parameters of type VARCHAR2. Then there have to be two string values provided. The first value goes to p1 and the second to p2. Quotation marks should not be used when setting input parameters unless they are part of the input value itself, since they are treated as escaped plain characters. For example, if the desired input value is TEST_VALUE1, the input parameter should be set as TEST_VALUE1, if you set it as "TEST_VALUE1", it will be recognized as \"TEST_VALUE1\". If you do not provide any parameters in the given Snap, you can still view the required input parameters in the Target Schema of the upstream Mapper Snap. The parameters are dynamically populated based on the column keys of the stored procedure; you can map the parameters and pass them as an input to the Stored Procedure Snap. Default value: [None] | ||||||
Snap execution | Select one of the three modes in which the Snap executes. Available options are:
|
Basic Use Case
The following pipeline describes how the Snap functions in a pipeline:
The Azure SQL Stored Procedure Snap invokes the Stored Procedure, Emp_Select_2,
The Stored Procedure as created on the Azure SQL Database:
Create PROCEDURE Emp_Select_2( @emp_id INT -- Input parameter ) AS BEGIN SELECT * FROM dbo.Emp_Details WHERE emp_id=@emp_id END
The value passed through the upstream:
The Azure SQL Stored Procedure Snap invokes the stored procedure EMP_Select_2:
The output parameters output preview:
The result set output preview:
Typical Snap Configurations
The key configuration for the Snap are:
The Azure SQL Stored Procedure Snap invokes a procedure Emp_Select on the database.
The procedure as created on the Azure SQL database:
- Without Expression: Directly passing the required values into the Azure SQL Stored Procedure Snap:
The Azure SQL Stored Procedure Snap invokes the stored procedure, EMP_Select, with the parameter values as provided through the upstream:
The upstream Snap passes the values for invoking the procedure:
The Stored Procedure Snap retrieves the Stored Procedure name ($SP_Name) dynamically from the Upstream and the Schema name (_Schema) from the pipeline parameters:
The Result Set output view that displays the results (the details of the employee with the provided ID) of the procedure:
Advanced Use Case
The following describes a pipeline, with a broader business logic involving multiple ETL transformations, that shows how typically in an enterprise environment, stored procedure functionality is used. Pipeline download link below.
This pipeline reads and moves the files from the SQL Server database to the Azure SQL database for reporting purposes. In this use case, the SQl Server Select Snap reads five records whose salary range is 40000 - 50000. The pipeline invokes a stored procedure, Emp_Select_SP, that retrieves the employee IDs where the salary>@sal. The Mapper Snap maps the value 50000 to the target output, sal. The Stored Procedure Snap invokes the procedure that retrieves all the records whose salary is greater than 50000.
Extract: The SQL Server Select Snap reads the records from the SQL Server Database.
Transform: The Mapper Snap maps the values to be used for the stored procedure.
Load: The Bulk Load Snap loads the records into the Azure SQL table.
- Extract: The Azure SQL Stored Procedure Snap retrieves the records as set in the stored procedure code.
The Stored Procedure as created on the Azure SQL Database:
Create PROCEDURE Emp_Select_SP ( @sal INT ) AS BEGIN SELECT * FROM dbo.employee_sp WHERE salary>@sal END
The out preview (5 records) from the SQL Server Select Snap:
The Output preview from the Azure SQL Stored Procedure Snap:
(2 records with employee salary greater than 50000 are retrieved)
Downloads
Important steps to successfully reuse Pipelines
- Download and import the pipeline into the SnapLogic application.
- Configure Snap accounts as applicable.
- Provide pipeline parameters as applicable.
Snap Pack History
Have feedback? Email documentation@snaplogic.com | Ask a question in the SnapLogic Community
© 2017-2024 SnapLogic, Inc.