• perireddy.arikatla (9/22/2013)


    Thanks For your Valuable Reply Sir.

    It works when i give tha Party_code in the where clause

    i.e

    SELECT party_code, sum(inst_amt) as total_insts,

    (Select Sum(paid_amt) as total_paid

    From party_payments

    Where paid_date < '11/27/2012' and party_code='HA20076'

    Group by party_code) as TotalPaid

    FROM party_payments where party_code='HA20076'

    GROUP BY party_code

    When i Run the query without giving party_code in where clause

    i.e

    SELECT party_code, sum(inst_amt) as total_insts,

    (Select Sum(paid_amt) as total_paid

    From party_payments

    Where paid_date < '11/27/2012'

    Group by party_code) as TotalPaid

    FROM party_payments

    GROUP BY party_code

    It was Giving Following Error

    Msg 512, Level 16, State 1, Line 1

    Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, <, <= , >, >= or when the subquery is used as an expression.

    Warning: Null value is eliminated by an aggregate or other SET operation.

    But My Requirement is Party Wise Total Inst_amt Value irrespective of Given Date and Total Paid< '11/27/2012' (i.e Given Date)

    Can Any body Help me Please

    Yes, we can but you have to provide some better data instead of going back and forth with questions that make everyone guess. Help us help you. For future posts, please use the methods for posting readily consumable found in the article at the first link under "Helpful Links in my signature line below .

    --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)