You must Sign In to post a response.
  • Category: SQL Server

    Sub total in Sql with query

    HI All,

    I have a table like this

    Voucher No. docid Voucher Date Ref Type Ref No Ledger Name Voucher type Narration Debit Amount Credit Amount Cheque/DD Cheque No Cheque Date Cost Category Cost Centre
    1 882497 1/10/2015 Office Supplies Cash Payment Sapphire Stamps 822 NULL
    1 882497 1/10/2015 Postage Cash Payment Courier to malad 50 NULL
    1 882497 1/10/2015 Cleaning Supplies Cash Payment Dusters 49 NULL
    1 882497 1/10/2015 Operating Supplies Cash Payment Oven Gloves 263 NULL
    1 882497 1/10/2015 Travel Cash Payment Travel to Vidyavihar 20 NULL
    2 882562 1/10/2015 Delivery Cost-Petrol Cash Payment 70 KFC Vashi Navi Mumbai
    3 882741 1/10/2015 Office Supplies Cash Payment Exp for Cash Audit book 238 KFC KFC R City Mall Ghatkopar Mumbai
    3 882741 1/10/2015 Small Wares Cash Payment Exp for Cotton Gloves 501 KFC KFC R City Mall Ghatkopar Mumbai
    3 882741 1/10/2015 Building Maintenance Cash Payment Exp for Black White Cement 140 KFC KFC R City Mall Ghatkopar Mumbai



    here i have a column name debit amout i want the sum of all the debit amount of a particular voucher in sub total row for each of the different voucher in next column to its debit amount.


    any help?
  • #763221
    Hi,

    SELECT SUM(Debit Amount) AS 'TotalDebitAmount', Voucher No. docid Voucher Date Ref Type Ref No Ledger Name Voucher type Narration Debit Amount Credit Amount Cheque/DD Cheque No Cheque Date Cost Category Cost Centre
    FROM TableX

    GROUP BY Voucher No,. docid, Voucher Date Ref Type, Ref No, Ledger Name, Voucher type, Narration ,Debit Amount, Credit Amount ,Cheque/DD ,Cheque No ,Cheque Date, Cost Category, Cost Centre,

    Hope this will help

    Regards
    Sriram.R


Sign In to post your comments