Link to home
Start Free TrialLog in
Avatar of kmc10314
kmc10314

asked on

SSIS Loop Container, Dynamic Loop Numbers

Hello, experts.
This is what I'm trying to do.
(1) Get company IDs from Table A and stored that into Table B with identity value, and company name (seq_num)

(2) Table B will look like this:

Seq_Num   |     Company
       1          |       ABCD
       2          |       EFGH
       3          |       IJKL
       4          |       MNOF

(3) The loop starts from value 1 and the ending value is total number of rows (on this example 4)

(4) As the package loops through it matches current cycle # and seq_num and gets the company ID

(5) The transformation task will get the company ID ans use it to pull the data for transformation.

(6) The package is going to stop once it loops through all #s of rows.....
Avatar of Brian Crowe
Brian Crowe
Flag of United States of America image

Please provide some schema information and if possible some sample source data.
Avatar of kmc10314
kmc10314

ASKER

Do you need schema information for the table that I pulled the data from?
Yes, I am trying to better understand your source(s) specifically "Table A" and "Table B".  At first glance you appear to be attempting to apply a procedural solution to a set-based problem.  SQL performs poorly at the former and excels at the latter so I want to make sure I understand what you're starting with.
I agree with BriCrowe.  From the looks of it what you need is a Data Flow Transformation with the following components:

o pull in the data from Table A using a source component
o hook that up to a Lookup Transformation to fetch values from some other table (you haven't really mentioned a name here) using your matching criteria
o finalize the flow with a destination component to write data to Table B

Ref Lookup Transformation [MSDN]

If you need to generate an increasing counter, one method is to handle this in the source query.  This is assuming you've got a SQL Server source.  Here's a simple example that demonstrates a method to generate an increasing counter:

with SomeData as (
	select distinct Color
	from DimProduct
)
select Color, ROW_NUMBER() over (order by (select null)) RN
from SomeData

Open in new window

Table A -- Load the data into temp table and assign identity as seq. number

SELECT IDENTITY(INT, 1, 1) AS Seq_Num, CH.CompID
INTO dbo.Scheduled_Load
FROM Level2WorkArea.dbo.CorpLoadCo CH
INNER JOIN Level2WorkArea.dbo.CorpLoadSchedule CS ON CH.CompID= CS.CompID
WHERE CS.ScheduleDate = CONVERT(DATE, GETDATE()) 

Open in new window


As a result the table will look like this

Seq_Num   |     Company
       1          |       ABCD
       2          |       EFGH
       3          |       IJKL
       4          |       MNOF

What I'm trying to do is that create a loopand match the loop number with the seq number.
The loop stops as it reach the max of the seq num.
ASKER CERTIFIED SOLUTION
Avatar of ValentinoV
ValentinoV
Flag of Belgium image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial