SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2005 Forums
 Other SQL Server Topics (2005)
 crosstab
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

taniarto
Starting Member

Indonesia
27 Posts

Posted - 06/29/2013 :  02:29:42  Show Profile  Reply with Quote
Dear All,
I Have data for example :
ID qty
A001 100
A001 100
B001 200
B001 100
C001 500

I want to make view like :
ID A001 B001 C001
A001 200 0 0
B001 0 300 0
C001 0 0 500

is it possible ?

thanks

visakh16
Very Important crosS Applying yaK Herder

India
52325 Posts

Posted - 06/29/2013 :  14:58:12  Show Profile  Reply with Quote

SELECT ID,[A001],[B001],[C001]
FROM (SELECT ID,ID AS PivotID,SUM(qty) AS qty
      FROM Table
      GROUP BY ID)t
PIVOT(SUM(qty) FOR PivotID IN ([A001],[B001],[C001]))p


------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page

madhivanan
Premature Yak Congratulator

India
22765 Posts

Posted - 07/23/2013 :  05:19:04  Show Profile  Send madhivanan a Yahoo! Message  Reply with Quote
And this is for dynamic PIVOT
http://beyondrelational.com/modules/2/blogs/70/posts/10840/dynamic-pivot-in-sql-server-2005.aspx

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.05 seconds. Powered By: Snitz Forums 2000