Back

How to Work with SQL Stored Procedures in SmartConnect

Published: Oct 08, 2025
Post Author Written by Maksudul Haq

SmartConnect integrates data across systems using maps and connectors. In addition to out-of-the-box functionality, you can extend your integrations by leveraging SQL stored procedures. Stored procedures can be used as data sources, destinations, and tasks, enabling you to transform, validate, and process data directly in SQL Server before or after your integration runs.

This article explains when and how to work with SQL stored procedures in SmartConnect, along with best practices.

Use tables when integration is straightforward.

Use stored procedures when you need logic, validation, security, or multi-table transactions.

SQL Stored Procedures Setup & Configuration

Instead of pointing to a table or view, you can execute more advanced queries with complex execution and data cleansing.

Useful for advanced queries where logic is managed from the SQL side not in SmartConnect

Example:

CREATE PROCEDURE [dbo].[SmartConnectDataSourceProcedure]
AS
BEGIN
    SELECT 
        VendorID, 
        Vendor_Name, 
        ProductName, 
        Price
    FROM 
        dbo.BC_PO
    WHERE 
        VendorID = 10000;
END
  1. Open SmartConnect
  2. Navigate to Data Sources > Bulk Sources > Query
  3. Create a MSSQL Query data source
  4. Execute your stored procedure in the Query

SmartConnect can call a stored procedure as a destination instead of writing directly to a table. Input parameters can be mapped from SmartConnect, and output parameters will be sent back to SmartConnect with success and failure statuses.

Useful for advanced destination with complex logic or multiple table relations

Example:

CREATE PROCEDURE [dbo].[SmartConnectProcedure]
	@VendorId VARCHAR(50),
	@VendorName VARCHAR (50),
	@PO_Id VARCHAR (50),
	@Product VARCHAR (50),
	@ProductName VARCHAR (50),
	@Quantity INT,
	@Price Float,
	@ErrorMessage VARCHAR(255) OUTPUT,
	@Error Int OUTPUT
AS 
BEGIN
BEGIN TRY

    -- ==========================================================
    -- Replace the section below with your own custom logic
    -- This is just a sample that inserts into BC_PO if the vendor is not on hold
    -- ==========================================================

    IF NOT EXISTS (
        SELECT [VendorID] 
        FROM [MyVendors] 
        WHERE [VendorID] = @VendorId 
          AND [HoldStatus] = 1
    )
        INSERT INTO dbo.BC_PO (
            [PO_Id],
            [VendorID],
            [Vendor_Name],
            [ProductId],
            [ProductName],
            [Quantity],
            [Price]
        )
        VALUES (
            @PO_Id, 
            @VendorId, 
            @VendorName, 
            @Product, 
            @ProductName, 
            @Quantity, 
            @Price
        )
    ELSE 
        SET @Error = 11 
        SET @ErrorMessage = 'Vendor is on hold'

    -- ==========================================================
    -- End of custom logic section
    -- ==========================================================

END TRY
BEGIN CATCH
    SET @Error = ERROR_NUMBER() 
    SET @ErrorMessage = ERROR_MESSAGE()
END CATCH

IF @Error IS NULL
BEGIN
    SET @Error = 0 
END
END
  1. Open SmartConnect > Integration Processes
  2. Add New or Open Process
  3. Navigate to the Target tab
  4. Select Microsoft Sql Server
  5. select Type Procedures
  6. Select your procedure to import into, and map it on the integration tab

As a Pre-Map Task

Run a stored procedure before the map executes before pulling data from the data source.

Useful for preparing staging data, truncating tables, or logging start time

As a Post-Document Task

Execute a stored procedure after the record is processed.

Useful for cleanup, logging, or flagging processed records

Input parameters accepted: Source Columns, Global Variables

As a Post-Map Task

Execute a stored procedure after the map completes.

Useful for cleanup, logging, or flagging processed records

Input parameters accepted: Global Variables

Troubleshooting

  • Procedure not showing in dropdown: Check that the SmartConnect SQL user has EXECUTE permission on the procedure.
  • No data returned: Test the stored procedure in SQL Management Studio.
  • Timeouts: Optimize queries and indexes if procedures take too long to run.

Summary

Using SQL stored procedures with SmartConnect gives you flexibility and control over how data is processed.

  • As data sources, they return only the data you want.
  • As destinations, they enforce logic, security, and multi-table operations.
  • As tasks or calculations, they help automate, validate, and optimize integrations.

By combining SmartConnect’s mapping capabilities with SQL stored procedures, you can build more powerful and reliable integrations.

Feeling stuck? Get the support and guidance you need to help you power through any data challenge

We're on your integration team. Connect with our people and let us know how we can help you.