Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Headers Problems

Author  Topic 

mjimenezh
Yak Posting Veteran

81 Posts

Posted - 2014-03-27 : 12:25:05
Hi, I almost found the solution to my Pivot problem,s now I don't know how to solve this details:

My actual view shows this :

Debcode|DebtorName|ItemCode|Year|1|2|3|4|5|6|7|8|9|10|11|12|
100 |Debtor100 | Item1 |2013|0|0|5|0|7|1|3|9|0|02|0 | 1|
100 |Debtor100 | Item1 |2014|2|1|4|
101 |Debtor101 | Item1 |2013|0|0|0|0|0|0|0|0|0| 1| 2| 5|
101 |Debtor101 | Item1 |2014|5|5|0|

And I Have to show this :

Debcode|DebtorName|ItemCode|201301|201302|... TO CURRENT MONTH

The problem is that this headers will be changing because the view shows from the actual month to 12 past months so, right now the headers are from march 2014 to march 2013 but the next month will be apr 2014 to apr2013 so I don't know how can I control this, my actual code is this :

SELECT     [DebCode],[Debtor],ItemCode, ItemDescription,[Year],[1],[2],[3],[4],[5],[6],[7],,[9],[10],[11],[12]
FROM (SELECT DebCode,Debtor,ItemCode,ItemDescription,Year,Month,Sold
FROM View_VK_ORDERS_SUMARY_F) AS PivotData
PIVOT
(SUM(Sold) FOR Month IN ([1],[2],[3],[4],[5],[6],[7],,[9],[10],[11],[12])) AS PIVOTING
order by year,debtor


Thanks in advace for your help

Lamprey
Master Smack Fu Yak Hacker

4614 Posts

Posted - 2014-03-27 : 12:29:30
http://stackoverflow.com/questions/10404348/sql-server-dynamic-pivot-query
Go to Top of Page
   

- Advertisement -