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
 Pivot

Author  Topic 

srimami
Posting Yak Master

160 Posts

Posted - 2012-02-08 : 13:59:13
Hi,

Can anyone please let me know the solution for my following requirement;

My source table is

Id Qty Price
1 1,1 10.99, 9.99
2 2,2,2 1.99, 20, 30

My target table should be in the following order

Id Qty1 Qty2 Qty3 Price1 Price2 Price3
1 1 1 NULL 10.99 9.99 NULL
2 2 2 2 1.99 20 30

The datatypes are Int, Varchar(250), Varchar(250) respectively for source table.

Can anyone please help me in achieving this using cursors or SP's.

Thank you,
Sri.

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-02-08 : 14:01:23
are number of Quantity and price values fixed? ie can there be only 3 values max for Quantity and price?

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

srimami
Posting Yak Master

160 Posts

Posted - 2012-02-09 : 16:12:36
The number can go upto 60 for Qty and price
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-02-09 : 17:48:04
so in those you want all 60 values to come in different columns?

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

srimami
Posting Yak Master

160 Posts

Posted - 2012-02-10 : 14:12:59
Yes
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-02-10 : 15:46:35
see

http://sqlblogcasts.com/blogs/madhivanan/archive/2007/08/27/dynamic-crosstab-with-multiple-pivot-columns.aspx

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -