• perireddy.arikatla (9/21/2013)


    I Think I Explained This Time Clearly

    A bit more clearer:rolleyes:. But again, this would be easier to come up with a solution if DLL and insert statements are provided!

    This might work, though it won't be a speed demon.

    SELECT party_code, sum(inst_amt) as total_insts,

    (Select Sum(paid_amt) as total_paid

    From @table t2

    Where t2.paid_date < '2012-11-27' and t2.party_code = t1.party_code

    Group by t2.party_code) as TotalPaid

    FROM @table t1

    GROUP BY party_code

    EDIT: Only air code. Test it!

    __________________________________________________________________________________________________________
    How to Post to get the most: http://www.sqlservercentral.com/articles/Best+Practices/61537/