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 2005 Forums
 Transact-SQL (2005)
 Need Query help

Author  Topic 

aswinjames
Starting Member

5 Posts

Posted - 2010-12-20 : 08:21:54
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

aswinjames
Starting Member

5 Posts

Posted - 2010-12-20 : 10:58:40
read 15 times!!
but no replies still
is the statement not clear?



Aswin James
Go to Top of Page

jimf
Master Smack Fu Yak Hacker

2875 Posts

Posted - 2010-12-20 : 11:27:29
Nope. See the link below.

Jim


http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Everyday I learn something that somebody else already knew
Go to Top of Page

aswinjames
Starting Member

5 Posts

Posted - 2010-12-20 : 12:04:07
Thanks jim,


Well, I have a source table
create table(customerid char, productid char, week1 int ,week2 int ,week3 int,week4 int,week5 int)

where the week column would hold the volume of products

the table would look as follows after applying a select statment

c1,p1,10,10,10,20,30

My O/p must be as follows

Custid,productid, Weekstart,weekend, Volume
c1, p1,w1,w3,10
c1,p1,w4,w4,20
c1,p1,w5,w5,30

Here repetitive volume would be avoided, The first row of the target table would be able to tel me that from w1 to w3 i had a volume of 10.

How do i achieve this?

Aswin James
Go to Top of Page

jimf
Master Smack Fu Yak Hacker

2875 Posts

Posted - 2010-12-20 : 13:06:44
And I bet this needs to be done dynamically - where the week starts and ends can change?

Jim

Everyday I learn something that somebody else already knew
Go to Top of Page

aswinjames
Starting Member

5 Posts

Posted - 2010-12-21 : 00:54:48
Jim,

The weekdates cant change, the week column is a integer field which has the details of the volume sold.

YA it needs to be sold dynamically.
But how?

Aswin James
Go to Top of Page
   

- Advertisement -