Showing posts with label execute ssis real time scenario. Show all posts
Showing posts with label execute ssis real time scenario. Show all posts

Thursday, July 3, 2025

Execute SQL Task in SSIS with Real-Time Scenarios

 

Execute SQL Task in SSIS with Real-Time Scenarios

The Execute SQL Task in SSIS is used to run SQL queries, stored procedures, or DDL/DML commands against a database. It is one of the most commonly used tasks in ETL (Extract, Transform, Load) processes.


Key Features of Execute SQL Task

  1. Executes T-SQL, PL/SQL, or other SQL statements depending on the connection manager.

  2. Can return single-row results, full result sets, or no results.

  3. Supports parameterized queries (input/output parameters).

  4. Can be used for:

    • Data manipulation (INSERT, UPDATE, DELETE)

    • Calling stored procedures

    • Creating/altering database objects (tables, views, etc.)

    • Logging and auditing ETL operations

    • Truncating tables before loading new data


Real-Time Scenarios for Execute SQL Task

1. Truncating a Staging Table Before Data Load

Scenario: Before loading new data into a staging table, you need to clear old records.
Solution: Use an Execute SQL Task to run TRUNCATE TABLE or DELETE.

sql
Copy
Download
TRUNCATE TABLE Staging.Customers;

Configuration:

  • Connection: OLE DB/SQL Server Connection Manager

  • SQL StatementTRUNCATE TABLE Staging.Customers;

  • Execution: Runs before the Data Flow Task that loads new data.


2. Logging ETL Process Start/End Times

Scenario: Track when an SSIS package starts and completes.
Solution: Insert timestamps into a logging table.

sql
Copy
Download
INSERT INTO ETL.AuditLog (PackageName, StartTime, Status) 
VALUES (?, GETDATE(), 'Started');

Configuration:

  • Connection: SQL Server Connection Manager

  • SQL Statement: Parameterized query (using ? or named parameters).

  • Parameters: Map PackageName from an SSIS variable.


3. Calling a Stored Procedure for Data Processing

Scenario: A stored procedure aggregates data before loading into a data warehouse.
Solution: Use Execute SQL Task to call the SP.

sql
Copy
Download
EXEC dbo.ProcessSalesData @Year = 2023, @Month = 12;

Configuration:

  • Connection: ADO.NET or OLE DB Connection Manager

  • SQL StatementEXEC dbo.ProcessSalesData @Year = ?, @Month = ?

  • Parameters: Map @Year and @Month from SSIS variables.