How to Execute multiple select statements in SSIS 2008 using Data flow task [closed]

Posted on

Question :

I am migrating data from one database to another database using SSIS package and i need to write multiple select statements for same table depending on conditions as mentioned below.

Actual Queries i need to add is

select * from tbldatasets where dataset = 104 and
ADDEDTIMESTAMP BETWEEN 
Convert(datetime, DateAdd(month, -2, Convert(date, GETUTCDATE())))
AND GETUTCDATE()

select * from tbldatasets where dataset = 106 and
ADDEDTIMESTAMP BETWEEN 
Convert(datetime, DateAdd(DAY, -10, Convert(date, GETUTCDATE())))
AND GETUTCDATE() 

select * from tbldatasets where dataset = 107 and
ADDEDTIMESTAMP BETWEEN 
Convert(datetime, DateAdd(MONTH, -1, Convert(date, GETUTCDATE())))
AND GETUTCDATE() 

My SSIS package is

enter image description here

in the above case only first query is executing. Is there any alternative to write multiple select statements should execute one after another and also
suggest me any tutorial links for SSIS learning.

Answer :

Make this your SQL Statement.

select * from tbldatasets where dataset = 104 and
ADDEDTIMESTAMP BETWEEN 
Convert(datetime, DateAdd(month, -2, Convert(date, GETUTCDATE())))
AND GETUTCDATE()
UNION ALL
select * from tbldatasets where dataset = 106 and
ADDEDTIMESTAMP BETWEEN 
Convert(datetime, DateAdd(DAY, -10, Convert(date, GETUTCDATE())))
AND GETUTCDATE() 
UNION ALL
select * from tbldatasets where dataset = 107 and
ADDEDTIMESTAMP BETWEEN 
Convert(datetime, DateAdd(MONTH, -1, Convert(date, GETUTCDATE())))
AND GETUTCDATE() 

This will combine you data of your seperate queries. for more information read up on TSQL @ https://msdn.microsoft.com/en-us/library/ms180026.aspx

Update your query by adding UNION ALL after each select statement

enter image description here

For tutorial you can watch the video series on youtube. https://www.youtube.com/watch?v=3cPq9FXk-RA&list=PLNIs-AWhQzcmPg_uV2BZi_KRG4LKs6cRs

For query you have to union your queries into a single resultset.

Leave a Reply

Your email address will not be published. Required fields are marked *