• skpanuganti (3/7/2010)


    select grp,sum([amount]) [amount],case when [grp]=1 then 'A01,A02,A03'

    when [grp]=2 then 'A22'

    else 'A33,A36' end [ledger]

    from dbo.sqlcentral

    group by grp

    -- replace 'dbo.sqlcentral' with your table name

    Thanks,

    Santosh

    That certainly works for the data given but I suspect that there might be just be a few more ledger entries than what was posted. 😉

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)