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
 SQL Server 2008 Forums
 Transact-SQL (2008)
 CTE, Unpivotting

Author  Topic 

aswinjames
Starting Member

5 Posts

Posted - 2010-12-20 : 10:59:51
Hey,
I have a table as follows

Customer|Product|w1|w2|w3|w4|w5|w6
C1|p1|10|10|10|20|20|40

The required output must be like
Cust|prod|WeekStart|weekend|volune
C1 |p1|w1|w3|10
C1|p1|w4|w5|20
C1|p1|w6|w6|40

One thing that needs to be done is UN pivoting.
How do I come up with week start and end dates..


Aswin James

robvolk
Most Valuable Yak

15732 Posts

Posted - 2010-12-20 : 11:31:56
See here for a similar Unpivot scenario:

http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=154010

Regarding week start and week end dates, you'll have to provide a more detailed example of the original data and the expected results.
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2010-12-21 : 08:38:03
In SQL Server 2008, we have VALUES caluse too
http://beyondrelational.com/blogs/madhivanan/archive/2010/08/02/values-clause-in-sql-server-2008.aspx

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -