Consulting

Results 1 to 1 of 1

Thread: Sleeper: Create Subtotals

  1. #1

    Sleeper: Create Subtotals

    Hi all,

    The following script creates the following table:
    select coalesce(cast(aa1.carriage_type as varchar(20)), 'Total Carriage') as 'Carriage_Type',
    round ( sum(aa1.new_charge), 0 ) as  'New Charge Ex GST'
    from 
    	( --AA1
    	select carriage_type, bss.New_Charges_Ex_Gst as new_charge from dbo.tbl_Accounts
    	inner join dbo.tbl_BillSummary bss on dbo.tbl_Accounts.ID = bss.Account_ID
    	) AA1
    group by AA1.Carriage_Type with Rollup

    I want to create a new row that says "Total Voice" which is sum of Fixed Voice and Mobile Voice

    and "Total Data" which is sum of Fixed Data and other data types I have.

    Is it easy to do in SQL 2008? I know I am not supposed to do this is SQL but i don't want to repeat it for 80 databases in Excel either, rather do it in SQL and use the query to import the table as a whole.
    Last edited by jjj2k; 04-05-2011 at 11:57 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •