Home > Database > Mysql Tutorial > How to Pass Variables as Parameters in an SSIS Execute SQL Task?

How to Pass Variables as Parameters in an SSIS Execute SQL Task?

Linda Hamilton
Release: 2025-01-06 18:16:40
Original
121 people have browsed it

How to Pass Variables as Parameters in an SSIS Execute SQL Task?

Passing Variables as Parameters in Execute SQL Task SSIS

Involving multiple database operations within an SSIS package often necessitates the dynamic setting of SQL parameters. Execute SQL Task in SSIS provides a convenient method for achieving this.

Suppose you have an SSIS package that retrieves data from a flat file and inserts it into a database table, utilizing an Execute SQL Task to create a temporary table using a parameterized query. You aim to make the query dynamic by passing parameters that specify date, portfolio ID, and stock type as variables.

To accomplish this within the Execute SQL Task:

1. Set SQLSourceType to Direct Input

This indicates that the SQL Statement property will directly specify the SQL query.

2. Define Variable Parameters in SQL Statement

Modify the SQL Statement to use question marks (?) as placeholders for the parameters. For instance:

CREATE TABLE [tempdb].dbo.##temptable 
(
date datetime,
companyname nvarchar(50),
price decimal(10,0),
PortfolioId int,
stype nvarchar(50)
)

Insert into [tempdb].dbo.##temptable (date,companyname,price,PortfolioId,stype) 
SELECT   date,companyname,price,PortfolioId,stype
FROM        ProgressNAV
WHERE     (Date = ?) AND (PortfolioId = ?) AND (stype in (?))
ORDER BY CompanyName
Copy after login

3. Map Variables to Parameters

In the Parameter Mapping section of the Execute SQL Task editor, add each parameter from the SQL Statement. Then, map each parameter to its corresponding SSIS variable:

| Parameter | SSIS Variable |
|---|---|
| Date | @Date |
| PortfolioId | @PortfolioId |
| stype | @Stypet |
Copy after login

4. Run the Task

Upon execution, the Execute SQL Task will inject the values assigned to these variables into the query, ensuring the appropriate data is retrieved and inserted into the temporary table.

The above is the detailed content of How to Pass Variables as Parameters in an SSIS Execute SQL Task?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template