Scenario:
In this video we will learn how to run multiple SQL Statements which are saved in a SQL Server Table. The new sql statement can be added or old can be deleted as per requirement. In any case we don't have to make any changes in SSIS Package to run the queries from SQL Server Table. SSIS Package will be dynamic to handle this.After watching this video, you will be able to learn
- How to Read the List of SQL Queries from SQL Server Table by using Execute SQL Task and save them into Object Type Variable
- How to Loop through List of SQL Queries By using Foreach Loop Container
- Save values from Foreach Loop Container to variable in SSIS Package
- Execute SQL Queries ( From Variable) by using Execute SQL Task
Scripts used in the Demo Video to Execute SQL Statements from a SQL Server Table in SSIS Package.
--Create Sample Tables for Testing, insert some records CREATE TABLE [dbo].[Customer_AS]( [CustomerId] [int] NULL, [CustomerName] [varchar](100) NULL, [StreetAddress] [varchar](100) NULL, [City] [varchar](100) NULL, [State] [char](2) NULL ) CREATE TABLE [dbo].[Customer_NA]( [CustomerId] [int] NULL, [CustomerName] [varchar](100) NULL, [StreetAddress] [varchar](100) NULL, [City] [varchar](100) NULL, [State] [char](2) NULL ) --Create the Table to save SQL Queries Create table dbo.QueryTable( Query NVARCHAR(MAX)) -- Alter Column as scenario changes or to handle rerun of Same Query Alter table dbo.QueryTable Add QueryRanStatus tinyint Alter table dbo.QueryTable Add Id int Identity(1,1) --Insert the Queries in the table Insert into dbo.QueryTable values ('insert into dbo.customer values(1,''Test1'')') Insert into dbo.QueryTable values ('Insert into dbo.Customer values (1000,''Test100'')') Insert into dbo.QueryTable values ('update [dbo].[Customer_NA] set CreatedOn=Null') Insert into dbo.QueryTable values ('Delete from [dbo].[Customer_AS] where FirstName=''Sukhjeet''') --Insert incorrect Query to Generate Error in SSIS Package Insert into dbo.QueryTable (Query,QueryRanStatus) values ('update [dbo].[Customer_NA] set CreatedOn=getdate(86'')',0) --Delete the Record from Table Delete from dbo.QueryTable where Query='Delete from [dbo].[Customer_AS] where FirstName=''Sukhjeet'')' --Test if all queries completed successfully. select * from dbo.customer --Truncate table dbo.customer Select * from [dbo].[Customer_NA] Select * from [dbo].[Customer_AS] where FirstName='Sukhjeet' --update the queires to rerun by using SSIS Package update dbo.QueryTable set queryranStatus=0 where id=3 --Check if queries ran successfully Select Query,ID ,QueryRanStatus from dbo.QueryTable where QueryRanStatus=0
Execute SQL Statements in SSIS Package from a SQL Server Table
Related Posts / Videos on Execute SQL Task
- Execute SQL Task Demo for Max Size of SQL Statement in Execute SQL Task Query Editor and Solution
- Execute SQL Task Demo- How to Build Dynamic SQL Query to Execute Multiple Stored Procedures those names are saved in a SQL Server Table
- Execute SQL Task Demo - How to Execute SQL Queries from Excel file in SSIS Package ( Record Set Destination, Object Type Variable and Foreach Loop Container Demo as well)
- Execute SQL Task Demo - How to use Single Row Result Set in Execute SQL Task and Control the Flow Tasks by using that value ( Precedence Constraint Demo as well).
- Execute SQL Task Demo - How to use Insert Query in Execute SQL Task and Map the variables to Parameters ( Insert File Name and Record Count after Loading the File).
- Execute SQL Task Demo - How to use Stored Procedure with Input/Output Parameters in Execute SQL Task in SSIS Package( Load File Name, Package Name , Record Count and File Load Time in SQL Server Table).
- Execute SQL Task Demo - How to build Query by using Variables in Execute SQL Task ( File Name validation and move files to Archive folder and Bad File Folder if does not validation correctly)
- Execute SQL Task Demo - How to use Full Result Set in Execute SQL Task ( Get Folder Path and File Names from SQL Table and Load those files)
- Execute SQL Task - How to Load Files from Specific Folder Paths Saved in a SQL Table By using SSIS Package
- Execute SQL Task ( use Variable value in Expressions Demo) - How to Reject Already Loaded Files and Load Only New Files in SSIS Package
- Execute SQL Task ( Handle Single Row Result Set Blank Error) -Single Row result set is specified, but no rows were returned in Execute SQL Task in SSIS Package
- Execute SQL Task ( Save Result Set to Variable Demo) - How to Return Deleted and Update
- Record Count from Execute SQL Task and Write to Flat File in SSIS Package
- Execute SQL Task ( Build Dynamic Query in Variable and use as Source ) - How to Save Query in Variable and Use in Execute SQL Task
- Execute SQL Task Expression's Demo - Using Variable in IF Clause in Execute SQL Task in SSIS Package
- Execute SQL Task ( Parameter Mapping Demo for Stored Procedures) - How to Run multiple Stored Procedure in Execute SQL Task with Input Parameters
- Read Single Cell Value from an Excel File in SSIS Package
This comment has been removed by the author.
ReplyDeleteI got question how to include the export Flatfile base on the Filedestination in the table?
ReplyDelete