Hi,
In SSIS 2005 Pivot Transformation is not giving expected Output.
Input table (Source table) Data:
Month | DaysOfWeek | Expenses |
January | Tuesday | 70 |
January | Thursday | 71 |
January | Friday | 72 |
January | Saturday | 73 |
January | Sunday | 74 |
January | Monday | 75 |
January | Wednesday | 76 |
February | Tuesday | 80 |
February | Thursday | 81 |
February | Friday | 82 |
February | Saturday | 83 |
February | Sunday | 84 |
February | Monday | 85 |
February | Wednesday | 86 |
March | Tuesday | 90 |
March | Thursday | 91 |
March | Friday | 92 |
March | Saturday | 93 |
March | Sunday | 94 |
March | Monday | 95 |
March | Wednesday | 96 |
Expected Output:
Month | Tuesday | Thursday | Friday | Saturday | Sunday | Monday | Wednesday |
January | 70 | 71 | 72 | 73 | 74 | 75 | 76 |
February | 80 | 81 | 82 | 83 | 84 | 85 | 86 |
March | 90 | 91 | 92 | 93 | 94 | 95 | 96 |
Output Generated by SSIS Package:
Month | Tuesday | Thursday | Friday | Saturday | Sunday | Monday | Wednesday |
January | 70 | 71 | 72 | NULL | NULL | NULL | NULL |
February | 80 | 81 | 82 | 83 | 84 | 85 | 86 |
March | 90 | 91 | 92 | 93 | 94 | 95 | 96 |
January | NULL | NULL | NULL | 73 | 74 | 75 | 76 |
Here January is coming as 2 rows?
PIVOT Transformation Configuration:
Input Columns:
Monthà1 (PivotUsage),LineageID=3241
DaysOfWeekà2 (PivotUsage),LineageID=3244
Expensesà3 (PivotUsage),LineageID=3247
Output Columns:
P_Monthà Configured SourceColumn =(LineageID=3241) & PivotKeyValue= (Blank)
P_Tuesdayà Configured SourceColumn =(LineageID=3247) & PivotKeyValue= (Tuesday). This is nothing but Value of columnDaysOfWeek
P_Thursdayà Configured SourceColumn =(LineageID=3247) & PivotKeyValue= (Thursday). This is nothing but Value of column DaysOfWeek
P_Fridayà Configured SourceColumn =(LineageID=3247) & PivotKeyValue= (Friday). This is nothing but Value of columnDaysOfWeek
P_Saturdayà Configured SourceColumn =(LineageID=3247) & PivotKeyValue= (Saturday). This is nothing but Value of columnDaysOfWeek
P_Sundayà Configured SourceColumn =(LineageID=3247) & PivotKeyValue= (Sunday). This is nothing but Value of columnDaysOfWeek
P_Mondayà Configured SourceColumn =(LineageID=3247) & PivotKeyValue= (Monday). This is nothing but Value of columnDaysOfWeek
P_Wednesdayà Configured SourceColumn =(LineageID=3247) & PivotKeyValue= (Wednesday). This is nothing but Value of columnDaysOfWeek
Source Table:
GO
/****** Object: Table [TEST].[PIVOT_THIS_SOURCE] Script Date: 12/02/2012 13:54:58 ******/
SETANSI_NULLSON
GO
SETQUOTED_IDENTIFIERON
GO
SETANSI_PADDINGON
GO
CREATETABLE [TEST].[PIVOT_THIS_SOURCE](
[Month] [varchar](15)NULL,
[DayOfWeek] [varchar](15)NULL,
[Expenses] [int] NULL
)ON [PRIMARY]
GO
SETANSI_PADDINGOFF
Target Table:
GO
/****** Object: Table [TEST].[PIVOTED_OUTPUT] Script Date: 12/02/2012 13:56:14 ******/
SETANSI_NULLSON
GO
SETQUOTED_IDENTIFIERON
GO
SETANSI_PADDINGON
GO
CREATETABLE [TEST].[PIVOTED_OUTPUT](
[Month] [varchar](15)NULL,
[Sunday] [varchar](15)NULL,
[Monday] [varchar](15)NULL,
[Tuesday] [varchar](15)NULL,
[Wednesday] [varchar](15)NULL,
[Thursday] [varchar](15)NULL,
[Friday] [varchar](15)NULL,
[Saturday] [varchar](15)NULL
)ON [PRIMARY]
GO
SETANSI_PADDINGOFF
Insert data Into source:
INSERT INTO TEST.PIVOT_THIS_SOURCE VALUES('January','Tuesday',70)
INSERT INTO TEST.PIVOT_THIS_SOURCE VALUES('January','Thursday',71)
INSERT INTO TEST.PIVOT_THIS_SOURCE VALUES('January','Friday',72)
INSERT INTO TEST.PIVOT_THIS_SOURCE VALUES('February','Tuesday',80)
INSERT INTO TEST.PIVOT_THIS_SOURCE VALUES('February','Thursday',81)
INSERT INTO TEST.PIVOT_THIS_SOURCE VALUES('February','Friday',82)
INSERT INTO TEST.PIVOT_THIS_SOURCE VALUES('February','Saturday',83)
INSERT INTO TEST.PIVOT_THIS_SOURCE VALUES('February','Sunday',84)
INSERT INTO TEST.PIVOT_THIS_SOURCE VALUES('February','Monday',85)
INSERT INTO TEST.PIVOT_THIS_SOURCE VALUES('February','Wednesday',86)
INSERT INTO TEST.PIVOT_THIS_SOURCE VALUES('March','Tuesday',90)
INSERT INTO TEST.PIVOT_THIS_SOURCE VALUES('March','Thursday',91)
INSERT INTO TEST.PIVOT_THIS_SOURCE VALUES('March','Friday',92)
INSERT INTO TEST.PIVOT_THIS_SOURCE VALUES('March','Saturday',93)
INSERT INTO TEST.PIVOT_THIS_SOURCE VALUES('March','Sunday',94)
INSERT INTO TEST.PIVOT_THIS_SOURCE VALUES('March','Monday',95)
INSERT INTO TEST.PIVOT_THIS_SOURCE VALUES('March','Wednesday',96)
INSERT INTO TEST.PIVOT_THIS_SOURCE VALUES('January','Saturday',73)
INSERT INTO TEST.PIVOT_THIS_SOURCE VALUES('January','Sunday',74)
INSERT INTO TEST.PIVOT_THIS_SOURCE VALUES('January','Monday',75)
INSERT INTO TEST.PIVOT_THIS_SOURCE VALUES('January','Wednesday',76)
Please anyone can correct if I am not doing it in correct way. Why it is not giving expected output?
http://www.rad.pasfu.com/index.php?/archives/14-PIVOT-Transformation-SSIS-Complete-Tutorial.html
http://www.bimonkey.com/2009/06/the-pivot-transformation/
http://www.codeproject.com/Articles/193842/Working-with-Pivot-and-UnPivot-Transformation
http://sujeev.wordpress.com/2011/05/16/pivoting-data-using-t-sql-and-ssis-pivot-transformation/
http://dinesql.blogspot.com.au/2011/08/pivot-and-unpivot-integration-services.html
Thanks Shiven:) If Answer is Helpful, Please Vote