May 7, 2017 at 4:09 am
hello all, i would like to seek your kind help regarding the transpose of rows into columns.
i have a table on the left hand side with more than 1000 company sales figure. I will use select distinct to pull each company from the table (sales), however i am having issue to populate each of the row (sales) into columns for easier review.
i would like to make a report for me to review those sales in a column format -15 columns (on the right hand side), can someone please kindly advice on how to build the TSQL for this?
Thanks.
May 7, 2017 at 5:07 am
Do you have to do this in T-SQL? Pivoting a data in T-SQL can be quite a costly process, and if you require it to be dynamic, even more so (plus you have to use Dynamic SQL).
Presentation layers are much better at this. For example using a Matrix on SSRS, or a Pivot Table in Microsoft Excel. Would tools like these instead be a viable option for you? If so, and you're not sure how to use them, then just ask, and we'll be able to show you how. 🙂
Thom~
Excuse my typos and sometimes awful grammar. My fingers work faster than my brain does.
Larnu.uk
May 7, 2017 at 1:45 pm
golden-1131024 - Sunday, May 7, 2017 4:09 AMhello all, i would like to seek your kind help regarding the transpose of rows into columns.
i have a table on the left hand side with more than 1000 company sales figure. I will use select distinct to pull each company from the table (sales), however i am having issue to populate each of the row (sales) into columns for easier review.
i would like to make a report for me to review those sales in a column format -15 columns (on the right hand side), can someone please kindly advice on how to build the TSQL for this?Thanks.
This is actually pretty simple to do in T-SQL and it can have some very good performance in the presence of a thing known as "pre-aggregation" (tip o' the hat to Peter Larsson for the term and the method). Please see the following article.
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs[/url]
--Jeff Moden
Change is inevitable... Change for the better is not.
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply