SQL Server - Stored Procedure

On this Page

Snap type:

Write

Description:

This Snap executes a stored procedure in a SQL Server database and writes the values of OUT parameters to the output view.


Expected upstream Snaps:  Any Snap with document output view

Expected downstream Snaps:  Any Snap with document input view

Expected input:  Input document may contain values for the Snap expression properties, typically for the Parameter values property.

Example:     "John" and "Smith" are values for the stored procedure's input parameters, the first and the second, respectively.

{
firstName: "John". lastName: "Smith" }

Expected output:   Output document in the output view contains a key-value pair for each output parameter. It will be an empty map document if there is no output parameter. Output document in the Result Set output view contains the result set of the stored procedure.


Prerequisites:

None


Support and limitations:
Account: 

This Snap uses account references created on the Accounts page of SnapLogic Manager to handle access to this endpoint. See Configuring SQL Server Accounts for information on setting up this type of account.


Views:
InputThis Snap allows up to one input view. If an input view is defined, then values from an incoming document can be used as input parameters to the stored procedure.
OutputThis Snap has exactly two document output views, one regular output view, and one Result Set output view.
Error

This Snap has at most one error view and produces zero or more documents in the view.

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.

ExampleaddSeventeen
Default value: [None] 


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\".

Default value: None.

If you do not provide any parameters in the 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.


Bypassing Parameters

If you wish to bypass any parameter then add a blank row in its place in this section. This is required since the Snap expects the parameters in the order in which they are defined.

For example, if there are three parameters and they are defined as Pipeline parameters _empid, _empname, and _loc and you wish to by pass the parameter _empname, then the Snap should be configured as:


Pass through 





If selected, the input document will be passed through to the output views under the key 'original'. The document will be passed to the Parameter output view, and it will also be passed to the Result Set output view if there is output sent from this view.

This property applies only to the Execute Snaps with SELECT statement or the Select Snaps. 

Default value: Not selected 


Snap Execution

Select one of the three modes in which the Snap executes. Available options are:

  • Validate & Execute: Performs limited execution of the Snap, and generates a data preview during Pipeline validation. Subsequently, performs full execution of the Snap (unlimited records) during Pipeline runtime.
  • Execute only: Performs full execution of the Snap during Pipeline execution without generating preview data.
  • Disabled: Disables the Snap and all Snaps that are downstream from it.

 The Snap does not support the custom type parameter since SQL Server JDBC driver lacks support for this feature. http://blogs.msdn.com/b/jdbcteam/archive/2012/04/03/how-would-you-use-table-valued-parameters-tvp.aspx


Examples


The following example is an application of the SQL Server Stored Procedure Snap for the example found at http://database.ittoolbox.com/groups/technical-functional/sql-server-l/example-of-code-that-overloads-a-sql-server-stored-procedure-5406272

Create a table called dbo.EMP by executing the following code:

CREATE TABLE [dbo].[EMP]( [EMPNO] [int] NOT NULL, [ENAME] [varchar](10) COLLATE SQL_Latin1_General_CP1_CI_AS NULL, [DEPTNO] [int] NOT NULL, CONSTRAINT [EMP_EMPNO_PK] PRIMARY KEY CLUSTERED ( [EMPNO] ASC )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] ) ON [PRIMARY]



Insert several rows:

INSERT INTO [dbo].[EMP] VALUES (1111,’EDWARDS’,10); 
INSERT INTO [dbo].[EMP] VALUES (2222,’ALLEN’,10); 
INSERT INTO [dbo].[EMP] VALUES (3333,’WATTS’,20); 
INSERT INTO [dbo].[EMP] VALUES (4444,’KIRAN’,20); 
INSERT INTO [dbo].[EMP] VALUES (5555,’CASTER’,20); 
INSERT INTO [dbo].[EMP] VALUES (6666,’VIJI’,30); 
INSERT INTO [dbo].[EMP] VALUES (7777,’DATTA’,30); 


Create a store procedure "EMP_PROC" with three input parameters:

CREATE proc [dbo].[EMP_PROC] @empno int=null, @ename varchar(10)=null, @deptno int=null AS IF EXISTS(SELECT 1 from [EMP] where EMPNO = @empno) BEGIN UPDATE [EMP] SET [EMPNO] = COALESCE(@empno,EMPNO), [ENAME] = COALESCE(@ename,ENAME), [DEPTNO] = COALESCE(@deptno,DEPTNO) WHERE EMPNO = @empno END

Build and execute the pipeline:

 The input data to the SQL Server - Stored Procedure Snap is:

{
        "EMPNO" : 1111,
        "ENAME" : "Ted",
        "DEPTNO" : 20 }

Only two input parameter values are provided while there are three input parameters in the procedure. This is possible because the procedure is written to support the overload feature. Executing the above pipeline will result in the update of ENAME value in the first row from "EDWARD" to "Ted".

Downloads

Important steps to successfully reuse Pipelines

  1. Download and import the Pipeline into SnapLogic.
  2. Configure Snap accounts as applicable.
  3. Provide Pipeline parameters as applicable.

  File Modified

File SQL Server Stored Procedure.slp

Feb 24, 2022 by Subhajit Sengupta

Snap Pack History

 Click to view/expand
Release Snap Pack VersionDateType  Updates
4.29main15993 Stable

Enhanced the SQL Server - Bulk Load Snap with the Batch Size field to process records in a batch.

4.28 Patch428patches14649 Latest

Enhanced the SQL Server - Select and SQL Server - Lookup Snaps with Option for Unique Identifier Column that allows you to convert the case to lower or upper while displaying the Unique Identifier output (display) value.

4.28main14627 StableUpdated the label for Delete Condition to Delete Condition (Truncates Table if empty) in the SQL Server Delete Snap.
4.27main12833 Stable

Enhanced the SQL Server - Execute Snap to invoke stored procedures.

4.26 Patch426patches12535Latest

Fixed an issue in the SQL Server Bulk Load snap where boolean data type failed to load into BIT field.

4.26main11181 StableUpgraded with the latest SnapLogic Platform release.
4.25 Patch425patches10797 Latest

Fixed an issue with the SQL Server - Bulk Load Snap where the Snap fails when the login password contains a colon or a less than (<) symbol.

4.25main9554
 
StableUpgraded with the latest SnapLogic Platform release.

4.24 Patch

424patches8657 Latest

Enhances the SQL Server - Select Snap by introducing a new field, Query Hints, which helps to customize and optimize the database engine to process query statements.

4.24main8556
Stable
  • Enhances the SQL Server - Select Snap to return only the selected output fields or columns in the output schema (second output view) using the Fetch Output Fields In Schema check box. If the Output Fields field is empty all the columns are visible.
  • Enhances the SQL Server - Stored Procedure to accept parameters from input documents by column keys. If the values are empty, the parameters are populated based on the column keys for easier mapping in the upstream Mapper Snap.
4.23 Patch423patches8190 Latest

Fixes an issue with SQL Server - Execute to handle SQL statements that begin with special characters.

4.23main7430
 
Stable

Enhances the accounts in this Snap Pack to allow Windows-based (Active Directory) authentication and user impersonation for SQL Server user accounts.

4.22 Patch

422patches6728 Latest

Enhances the SQL Server Snap pack to allow Windows (Active Directory) based authentication and user impersonation for SQL Server user accounts.

4.22main6403
 
StableUpgraded with the latest SnapLogic Platform release.

4.21 Patch

421patches6272 Latest

Fixes the issue where Snowflake SCD2 Snap generates two output documents despite no changes to Cause-historization fields with DATE, TIME and TIMESTAMP Snowflake data types, and with Ignore unchanged rows field selected.

4.21 Patch

421patches6144 LatestFixes the following issues with DB Snaps:
  • The connection thread waits indefinitely causing the subsequent connection requests to become unresponsive.
  • Connection leaks occur during Pipeline execution.

4.21 Patch

MULTIPLE8841 Latest

Fixes the connection issue in Database Snaps by detecting and closing open connections after the Snap execution ends. 

4.21 Patch 

db/sqlserver8837 Latest

Fixed the SQL Server - Stored Procedure Snap to support the UUID datatype.

4.21snapsmrc542

 

StableUpgraded with the latest SnapLogic Platform release.

4.20 Patch 

db/sqlserver8793 Latest

Fixed an issue in the SQL Server - Insert Snap due to which the Snap failed to load values of data type INT.

4.20 Patch 

db/sqlserver8796 Latest

Fixed the SQL Server - Bulk Load Snap to mask the password in the logged exception messages

4.20snapsmrc535
 
StableUpgraded with the latest SnapLogic Platform release.

4.19 Patch 

db/sqlserver8413 Latest

Fixed an issue with the SQL Server - Update Snap wherein the Snap is unable to perform operations when:

  • An expression is used in the Update condition property.
  • Input data contain the character '?'.
4.19snaprsmrc528
 
StableUpgraded with the latest SnapLogic Platform release.

4.18 Patch

 db/sqlserver7989 Latest

Fixed an issue in the SQL Server - Merge Snap wherein identity columns are not handled correctly. Also, added a field, Enable Identity Insert, that enables you to insert values into an identity column.

4.18snapsmrc523
 
Stable
  • Added support for SQL Server account Active Directory authentication for SQL server for driver JAR version mssql-jdbc-6.2.2-jre8.jar.
  • Reverts a 4.17-patch (db/sqlserver7394) update regarding how BIT and BOOLEAN column data type values are displayed. They now display as true or false (4.17 GA behavior in snapsmrc515) rather than converting to 0 or 1 values (4.17-patch behavior).
4.17 PatchMULTIPLE7479 Latest

Fixed an issue with the SQL Server - Lookup Snap wherein it fails a UUID search.

4.17ALL7402
 
Latest

Pushed automatic rebuild of the latest version of each Snap Pack to SnapLogic UAT and Elastic servers.

4.17snapsmrc515
 
Latest
  • Fixed an issue with the SQL Server Execute Snap wherein the Snap would send the input document to the output view even if the Pass through field is not selected in the Snap configuration. With this fix, the Snap sends the input document to the output view, under the key original, only if you select the Pass through field.
  • Added the Snap Execution field to all Standard-mode Snaps. In some Snaps, this field replaces the existing Execute during preview check box.

4.16 Patch

 db/sqlserver6981 Latest

Fixed an issue of slow performance in SQL Server Snaps while using SQL Server Dynamic account type. 

4.16 Patch db/sqlserver6818 Latest

Fixed an issue with the Lookup Snap passing data simultaneously to output and error views when some values contained spaces at the end.

4.16snapsmrc508
 
StableUpgraded with the latest SnapLogic Platform release.

4.15 Patch

 db/sqlserver6337 Latest

Replaced Max idle time and Idle connection test period properties with Max life time and Idle Timeout properties respectively, in the Account configuration. The new properties fix the connection release issues that were occurring due to default/restricted DB Account settings.

4.15snapsmrc500
 
StableUpgraded with the latest SnapLogic Platform release.

4.14 Patch 

db/sqlserver5912 Latest

Fixed an issue to parse the right data type and display it in the input schema for SQL Server Snap..

4.14 Patch 

db/sqlserver5665 Latest

Implemented a connection retry logic in the SQL Server account to resolve the connection loss issue in a customer's org.

4.14snapsmrc490
 
StableUpgraded with the latest SnapLogic Platform release.
4.13

snapsmrc486

 
StableUpgraded with the latest SnapLogic Platform release.
4.12

snapsmrc480

 
StableUpgraded with the latest SnapLogic Platform release.

4.11 Patch 

db/sqlserver4388 Latest

Fixed an issue with the Stored Procedure Snap that does not maintain the columns' order on the output as per table's definition.

4.11 Patch

 db/sqlserver4288 Latest

 SQL Server Snap Pack - Fixed an issue when inserting a valid NaN value into a column.

4.11snapsmrc465
 
StableUpgraded with the latest SnapLogic Platform release.

4.10 Patch

sqlserver3953 Latest

Fixed an issue where the SQL Server Stored Procedure gets hanged when more than one Snap existed in the pipeline each processing greater than 1K documents.

4.10

snapsmrc414

 
Stable

Added Auto commit property to the Select and Execute Snaps at the Snap level to support overriding of the Auto commit property at the Account level.

4.9.0 Patch

sqlserver3224 Latest

Addressed an issue with SQL Server - Bulk Load execution even with 0 input documents

4.9.0 Patch

sqlserver3076 Latest

Fixed an issue regarding connection not closed after login failure; Expose autocommit for "Select into" statement in PostgreSQL Execute Snap and Redshift Execute Snap

4.9snapsmrc405
 
StableUpgraded with the latest SnapLogic Platform release.

4.8.0 Patch

sqlserver2803 Latest

Addressed an issue with slow performance with Bulk Load BCP.

4.8.0 Patch

sqlserver2761 Latest

Potential fix for JDBC deadlock issue.

4.8.0 Patch

sqlserver2706 Latest

Fixed SQL Server Snap Pack rendering dates that are one hour off from the date returned by database query for non-UTC Snaplexes.

4.8

snapsmrc398

 
StableUpgraded with the latest SnapLogic Platform release.
4.7

snapsmrc382

 
Stable
  • Extended support for SQL Server Dynamic accounts.
  • Updated the SQL Server Stored Procedure Snap with the Pass through field. 
4.6snapsmrc362
 
Stable
  • Resolved an issue in SQL Server Bulk Load Snap that caused BCP program related failures.
  • Enhanced to fully support SQL statements with/without expressions & SQL bind variables.
  • Resolved an issue that caused failures when executing merge statements.
4.5.1

snapsmrc344

 
LatestUpgraded with the latest SnapLogic Platform release.
4.5

snapsmrc344

 Stable
  • Resolved an issue in SQL Server Execute Snap that erroneously reported a database/schema mismatch during Snap/pipeline execution.
  • Resolved an issue in SQL Server Lookup Snap that occurred when handling case-insensitive field values.
4.4.1NA Latest
  • Introduced the SQL Bulk Load in this release.