Question

I have to input rows of data where no month is given with. It has to have a month and a year. In my package i use a multicast to sent it to 12 derived columns where i want to add the Year and the month. I thought it would be like joining two numbers:

"2013" + "005" = 2013005

Since the year got to be a variable:

"Period" + "005" = Not Possible
"Period" + "Month5" = Not Possible

What am i missing, are there better ways to do this?

A full example of a row and how it should get:

1 702091    120 5   120_5   7650    638 M082    702091

should become

1 702091    120 5   120_5   7650    638 M082    702091 2013001
1 702091    120 5   120_5   7650    638 M082    702091 2013002
1 702091    120 5   120_5   7650    638 M082    702091 2013003
1 702091    120 5   120_5   7650    638 M082    702091 2013004
1 702091    120 5   120_5   7650    638 M082    702091 2013005
1 702091    120 5   120_5   7650    638 M082    702091 2013006
1 702091    120 5   120_5   7650    638 M082    702091 2013007
1 702091    120 5   120_5   7650    638 M082    702091 2013008
1 702091    120 5   120_5   7650    638 M082    702091 2013009
1 702091    120 5   120_5   7650    638 M082    702091 2013010
1 702091    120 5   120_5   7650    638 M082    702091 2013011
1 702091    120 5   120_5   7650    638 M082    702091 2013012
Was it helpful?

Solution

You have an SSIS Variable with a data type of int. The desire is to do string-like concatenation to append month data to it.

The cheap route is to cast your integer to string, concatenate your values and then cast back to a numeric data type. Don't do that. Your opportunity for error handling is less than stellar with the SSIS expression language plus it's horribly inefficient.

The better route is to use math. You have 2013 You'd like to get to 2013001...2013012 Mathematically add enough zeros to the end of 2013 until your months fit and then do regular addition. 2013 * 1000 + 1 ... 2013 * 1000 + 12

A Query would look like

SELECT
    BASE.year_number + MONTHS.month_number
FROM
    (
        SELECT 2013 * 1000
    ) BASE (year_number)
    CROSS JOIN
    (
        SELECT TOP 12
            ROW_NUMBER() OVER (ORDER BY (SELECT NULL)) AS n
        FROM
            information_schema.COLUMNS ISC  
    ) MONTHS(month_number);

In SSIS, the same concept will apply. Add a derived column, call it YearBase and for the value, it will be @[User::MyYearVariable] * 1000. Now the downstream components will be able to access the column "YearBase."

Option 1

Use Multicast is to split it 12 times and add a Dervied column to that output. In those Derived Columns, create another column, ComputedYearMonth type of int32 and then set your formula to be [YearBase] + 1 ... [YearBase] + 12.

Option 2

I'm lazy. I assume that after the derived column stuff in option 1, you're probably going to bring all those rows back together with a union all. You can do that, but that's about 16 more boxes on a data flow than I'd care to maintain. Never reach for the script component as your first tool of choice but for a situation like this, I'd probably use it. Drag a Script Component onto your canvas and configure it to operate in Asynchronous mode and then push the above logic into the script.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top