Pivot query

  • 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 :

    monthcountcode

    68425DELIVERY

    620CANCELLED

    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.

    Thanks

  • Please don't cross post. It just wastes people's time and fragments replies.

    No replies to this thread please. Direct replies to http://www.sqlservercentral.com/Forums/FindPost870654.aspx

    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

Viewing 2 posts - 1 through 1 (of 1 total)

You must be logged in to reply to this topic. Login to reply