i have two tables in SQL Server 2008, in one i have the needs of articles per week, and in another i have the stock, somethin like
NEEDS:
Article Week Need
--------------------------------------------------------------------
aa 1 25
aa 2 13
aa 4 33
aa 6 21
aa 25 40
ab 1 1
ab 2 3
ab 16 14
ab 50 50
STOCKS
Article Units
---------------------------------------------------------------------------
aa 80
ab 14
ac 8
and i need to show something like:
Article WEEK1 WEEK2 WEEK4 WEEK6 WEEK16 WEEK25
needs stock needs stock needs stock needs stock needs stock needs stock
aa 25 80 13 55 42 22 21 20 0 -1 40 -1
ab 1 14 3 13 0 10 0 10 14 10 0 -4
This will show in Encel, for this i use C# and T-SQL, my problem is that if use PIVOT i can oly do it with the needs per week but i expect the needs and the stock, if i do without the pivot i can obtain the article the week an the stock, save the data in objects and do the calculation of the stock per week and then format the Excel, but i have one problem i need in the object something like:
puclic class needsPerWeek
{
string Article{get;set;}
int needsWeek1{get;set;}
int stockWeek1{get;set;}
int needsWeek2{get;set;}
int stockWeek2{get;set;}
int needsWeek{get;set;}
int stockWeek4{get;set;}
int needsWeek6{get;set;}
int stockWeek6{get;set;}
int needsWeek16{get;set;}
int stockWeek16{get;set;}
int needsWeek25{get;set;}
int stockWeek25{get;set;}
int needsWeek50{get;set;}
int stockWeek50{get;set;}
....
....
}
but i don´t know how much weeks i will recibe.
So, can i do this with pivot?, or any other way to obtain this?