SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Query for Subtotal and Grand total
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

jdeforums
Starting Member

India
8 Posts

Posted - 02/21/2014 :  06:24:09  Show Profile  Reply with Quote
Hi,

I required Subtotal based on branch wise and Grand total.

My current query is Select SDMCU as Branch,ABAC29_DESC as

Sales,ABAC30_DESC as Type,round(sum(case when invoice_date=dateadd(day,datediff(day,0,getdate()),-1) then order_qty*unit else 0 end)/1000000,2) as Previousday_Sales_Million,round(sum(order_qty*unit)/1000000,2) as MTD_Sales_Million from sales where invoice_date >= dateadd(month,datediff(month,0,getdate()),0) and invoice_date < dateadd(month,datediff(month,0,getdate())+1,0) group by ABAC29_desc,abac30_desc,sdmcu order by sdmcu

And required output is

ITM 3rd Other 0 2.64
ITM 3rd Home 0 0.06
ITM Inter Home 0.96 15.45
Total 0.96 18.15
ITR 3rd Other 1.22 2.24
ITR 3rd Home 0 0.23
ITR Inter Home 0.44 24.26
Total 1.66 26.73
Grand Total 2.62 44.88

Please help me to create the query based on my request

Thanks in advance



Suresh.K.P
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.36 seconds. Powered By: Snitz Forums 2000