December 12, 2018 at 5:40 pm
I have a data set that looks like this.
Type | Col1 | Col2 | Col3 | Col4 | Col5 | Col6 |
Row1 | 10 | 10 | 10 | 10 | 10 | 10 |
Row2 | 10 | 10 | 10 | 10 | 10 | 10 |
Row3 | 10 | 10 | 10 | 10 | 10 | 10 |
Row4 | 10 | 10 | 10 | 10 | 10 | 10 |
I want it to look like this
Type | Row1 | Row2 | Row3 | Row4 |
Col1 | 10 | 10 | 10 | 10 |
Col2 | 10 | 10 | 10 | 10 |
Col3 | 10 | 10 | 10 | 10 |
Col4 | 10 | 10 | 10 | 10 |
Col5 | 10 | 10 | 10 | 10 |
Col6 | 10 | 10 | 10 | 10 |
There may be more or less rows and each row will have a different type The columns will be fixed. I don't need to do any calculations.
I thought this would be straight forward but I guess not.
December 13, 2018 at 11:03 am
It's not a simple pivot. It's a combination of a pivot and an unpivot. And, because the number of rows isn't constant, it will need to be dynamic.
I have to ask WHY!!!
Drew
J. Drew Allen
Business Intelligence Analyst
Philadelphia, PA
December 13, 2018 at 11:10 am
I have output of table 1 already. The boss has asked for the data to be pivoted. Mine is not to ask why.
December 13, 2018 at 11:56 am
Declare @Rows varchar(max)
,@Cols varchar(max)
,@DynamicPivotQuery nvarchar(max)
Viewing 4 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply
This website stores cookies on your computer.
These cookies are used to improve your website experience and provide more personalized services to you, both on this website and through other media.
To find out more about the cookies we use, see our Privacy Policy