SQL Queries

Gary August 1 Reputation point
2021-06-11T21:35:01.017+00:00

In SSIS I need to run two queries, so that the output from the first will become input into the second query. The first query I have uses an OLE DB Source and creates output with several records. I would like to use the output from the first query as input into a second query to further filter and aggregate the records. I would like to do this without using a stored procedure. I have read about using result sets to pass to stored procedures, but there should be a more straight forward way of doing this. I have also tried saving the results of the first sql query into a temporary table and then using the temp table as input into the second query, but I get errors doing that in OLE DB Source. Can you please provide me with a simple way of doing this? An example would be most appreciated.

SQL Server Integration Services
SQL Server Integration Services
A Microsoft platform for building enterprise-level data integration and data transformations solutions.
2,564 questions
{count} votes

2 answers

Sort by: Most helpful
  1. Praveen Babu Vejandla 26 Reputation points
    2021-06-12T09:47:56.907+00:00

    Using CTE or subqueries with derived tables in a single SQL query and running it through Execute SQL Task in SSIS could be an option.

    1 person found this answer helpful.
    0 comments No comments

  2. ZoeHui-MSFT 36,116 Reputation points
    2021-06-14T05:44:48.997+00:00

    Hi @Gary August ,

    As @Praveen Babu Vejandla said, CTE is a good way to resolve the issue.

    More details you may refer:

    with-common-table-expression-transact-sql

    Regards,

    Zoe


    If the answer is helpful, please click "Accept Answer" and upvote it.

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.
    Hot issues October

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.