Click here to monitor SSC
SQLServerCentral is supported by Redgate
Log in  ::  Register  ::  Not logged in
Home       Members    Calendar    Who's On

Add to briefcase

Pivot query Expand / Collapse
Posted Monday, February 22, 2010 12:51 PM


Group: General Forum Members
Last Login: Wednesday, December 30, 2015 2:11 PM
Points: 17, Visits: 368
HI All,

I am trying to convert rows to columns using Pivot function. Here is my case

SELECT Month(a.createddate) as month,
count(statusid) as count,b.code
from ServiceRequest a,
StdActivity b
where a.createddate between '2009-06-01 00:00:00.000' and '2009-12-30 23:59:59.999'
--and statusid=10
and a.SRSetnumber like '%DELI%'
and a.statusid=b.StdActivityID
group by Month(a.createddate),a.statusid ,b.code
order by Month(a.createddate) ,a.statusid,b.code

Result Set :

month count code

i want to use pivot function and convert the result set to

month delivery cancelled
6 8425
6 20

Any help would be greatly appreciated. Writing a reporting query and got stuck up with this .I havent used the pivot before and the help topics is little bit confusing to me.

Post #870652
Posted Monday, February 22, 2010 1:08 PM



Group: General Forum Members
Last Login: Saturday, December 3, 2016 5:18 AM
Points: 45,619, Visits: 44,147
Please don't cross post. It just wastes people's time and fragments replies.
No replies to this thread please. Direct replies to

Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

We walk in the dark places no others will enter
We stand on the bridge and no one may pass

Post #870671
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse