Domanda

I am practicing SSIS and currently working on Pivot transformation. Here's what i am working on. I created a Data Source (Table name: Pivot) with the following data.

enter image description here

Using SSIS, i created a package for Pivoting the data to have the following columns

PersonID --- Product1 --- Product2 --- Product3.

Here's where am at, I was able to create the pivot data to text file. But The output is not grouped by PersonID.

My Current Output is

enter image description here

As we can see the Transformation does not group the based on SetKey(PersonID : PivotUsage =1)

The output i am hoping to get is

enter image description here

Where the data is grouped based on PersonID.

What am i missing here?

Edit: Going back to the example i was following, I re-ordered the input data as follows.

enter image description here

Does the Input data need to be in this order/pattern, every time? Most of the examples i came across follow the similar pattern.

È stato utile?

Soluzione

Yes, the input data needs to be sorted by whatever you're pivoting on:

To pivot data efficiently, which means creating as few records in the output dataset as possible, the input data must be sorted on the pivot column. If the data is not sorted, the Pivot transformation might generate multiple records for each value in the set key, which is the column that defines set membership. For example, if the dataset is pivoted on a Name column but the names are not sorted, the output dataset could have more than one row for each customer, because a pivot occurs every time that the value in Name changes.

That's a direct quote from the Pivot Transformation documentation on MSDN. (Emphasis added.)

Altri suggerimenti

When I first read this answer, I thought that the sorted column should be the one with PivotUsage=2 in the pivot. That's what I understood the pivot column to be. However, what finally worked for me was to sort by a column with pivot usage=1. It's a column I would group by if writing the sql by hand.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top