Click here to Skip to main content
15,886,963 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

In SSIS when you create a variable for a package, I know how to create a SQL statement in the variables expression, but is it possible to assign the result of the SQL statement in the expression to a variable and then used as a parameter in an Execute SQL Task?

I know this can be done using two Execute SQL task where first Execute SQL task runs the SQL query that I am looking to use in an expression, then second Execute SQL task uses value found in first Execute SQL task as a parameter, but I am trying to process both in one Execute SQL task. Can this be done please?

Thanks

What I have tried:

Viewed numerous youTube tutorials, attempted several various methods but Expression built SQL just shows SQL text in variable assigned to it
Posted
Comments
Member 15627495 3-Mar-24 11:22am    
hello !

you can use 'sub query','nest query' :
it's simple, one query will use another query as 'input parameter' as criteria.


// above two queries in one statement.

select * from 'table' where id IN ( select id from 'another_table' )


jar8695 12-Mar-24 15:59pm    
Thanks - this gave me something to go on. See solution

1 solution

I have implemented this using a sub-query within the INSERT INTO in the SSIS SQL task's SQL statement. I first created the required SSIS package variables that will be used as input parameters to the SQL task then the additional value required form SQL is in sub-query within the VALUES portion of the INSERT INTO. I was not previously aware you could use a sub-query within the VALUES portion of INSERT INTO

INSERT INTO myTable1 (ColumnA, ColumnB, ColumnC)
Values (?, ?, (SELECT COUNT(ID) FROM myTable2));
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900