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
 General SQL Server Forums
 New to SQL Server Programming
 SQL Pivot help
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

w1102157
Yak Posting Veteran

80 Posts

Posted - 07/15/2012 :  17:31:59  Show Profile  Reply with Quote
Hi Guys

i am doing a task at work where i need to present the data in a pivot for example

currently the data is like the blow

type Name count
open TT 567
open AA 56
closed TT 34
closed AA 100

i need to present the above data like

TT TT AA AA
open closed Open Closed
567 34 56 100

Is there any way i can do this?

thank you

visakh16
Very Important crosS Applying yaK Herder

India
47069 Posts

Posted - 07/15/2012 :  22:01:16  Show Profile  Reply with Quote

SELECT SUM(CASE WHEN type = 'open' AND Name ='TT' THEN [count] ELSE 0 END) AS TTOpen,
 SUM(CASE WHEN type = 'closed' AND Name ='TT' THEN [count] ELSE 0 END) AS TTClosed,
 SUM(CASE WHEN type = 'open' AND Name ='AA' THEN [count] ELSE 0 END) AS AAOpen,
 SUM(CASE WHEN type = 'closed' AND Name ='AA' THEN [count] ELSE 0 END) AS AAClosed
FROM Table


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

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.08 seconds. Powered By: Snitz Forums 2000