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)
 Pivot type question

Author  Topic 

NeilG
Aged Yak Warrior

530 Posts

Posted - 2009-11-16 : 05:35:01
Hopefully somone can help on this one, we have a table (see below)

SELECT
[Type]
[Employee],
Sales_One,
Sales_Two,
Sales_Three
FROM
SalesData

Within this table, there are three types 'Order', 'Proposal','Possible'

Where tying to get the infomation to display like

Employee, 'Order_Sum','Proposal_Sum','Possible_Sum'
John , 10 , 1 ,4
David, 11, 2 ,4




I've looked at pivot union etc but i just can't seem to figure out how to do this, can anyone help

-----------------------------------------------
Learning something new on SQL Server everyday.

NeilG
Aged Yak Warrior

530 Posts

Posted - 2009-11-16 : 06:51:29
bump
Go to Top of Page

bklr
Master Smack Fu Yak Hacker

1693 Posts

Posted - 2009-11-16 : 07:15:14
see this link
http://sqlblogcasts.com/blogs/madhivanan/archive/2007/08/27/dynamic-crosstab-with-multiple-pivot-columns.aspx

or post some sample data

sample example
select employee,[order]as 'order_sum',[proposal]as 'Proposal_sum',[possible] as 'possible_sum'
from tablename
pivot ((sum(colname) for type in ([order],[proposal],[possible]))pvt
Go to Top of Page

NeilG
Aged Yak Warrior

530 Posts

Posted - 2009-11-16 : 11:35:38
Thanks I think i've cracked it using the PIVOT function
Go to Top of Page
   

- Advertisement -