• Here you go:

    CREATE TABLE Payment

    (

    PaymentHistoryID INT,

    paymentID INT,

    Amount DECIMAL(10, 2),

    receivedType CHAR(2),

    Reason VARCHAR(10)

    );

    INSERT INTO Payment

    VALUES

    (1,11, 5000.00,'Dr','ASD'),

    (2,12, 4000.00,'Cr', 'BG'),

    (3,11, 8000.00,'Cr', 'BG'),

    (4,11, 3000.00,'Dr', 'SD'),

    (5,11, 3000.00,'Cr','ASD'),

    (6,13,50000.00,'Cr','ASD'),

    (7,13,50000.00,'Cr','ASD'),

    (8,13, 1000.00,'Cr','ASD'),

    (9,13, 500.00,'Cr','ASD')

    SELECT paymentID,

    Sum(CASE receivedType

    WHEN 'Dr' THEN Amount

    ELSE -1 * Amount

    END) Amount,

    Reason

    FROM Payment

    GROUP BY paymentID,

    Reason

    demonfox (2/4/2013)


    Please provide the ddl ..

    follow this link for best practices to post :

    http://www.sqlservercentral.com/articles/Best+Practices/61537/

    Always provide DDL along with test data and expected result, as mentioned by demonfox...

    ~ Lokesh Vij


    Guidelines for quicker answers on T-SQL question[/url]
    Guidelines for answers on Performance questions

    Link to my Blog Post --> www.SQLPathy.com[/url]

    Follow me @Twitter