Microsoft SQL Server
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsDatabasesMicrosoft SQL Server

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old December 9th, 2005, 04:39 PM
j_jst j_jst is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Sep 2004
Posts: 2 j_jst User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 11 m 13 sec
Reputation Power: 0
Question Converting Rows into Columns...(Cross Tab)

Hi genius,


I got the result set as shown below (By executing another query i got this).

Month Status Count
===== ====== =====
April I 129
April O 4689
April S 6
July I 131
July O 4838
July S 8
June I 131
June O 4837
June S 8
May I 131
May O 4761
May S 7

But, I need the same result set as below. How to convert like below

Month I O S
===== = = =
April 129 4689 6
July 131 4838 8
June 131 4837 8
May 131 4761 7

Can anyone provide me the tips/solution.

Thanks in advance

Regards,
j_jst

Reply With Quote
  #2  
Old September 18th, 2007, 07:37 AM
bcsr4u bcsr4u is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Sep 2007
Posts: 1 bcsr4u User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 16 m 33 sec
Reputation Power: 0
Post Using Pivot Operator, we can do this

Hi
Here is my query that i wrote in sqlserver2005

SELECT [Month],[I],[O],[S]
FROM ( SELECT [Month]
, Status,CountS
FROM test
) p PIVOT (max(CountS)
FOR [Status] IN ([I],[O],[S])
) AS pvt
ORDER BY [Month]

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsDatabasesMicrosoft SQL Server > Converting Rows into Columns...(Cross Tab)


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway
Stay green...Green IT