Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Query for Sale

Author  Topic 

jdeforums
Starting Member

8 Posts

Posted - 2014-02-13 : 06:04:59
Hi ,

I have query to download sale summary value in monthwise, but now i want to include previous days sale and total sales as mentioned below format .

Sales Type Month_sales
3rd Domes XXX
3rd Export XXX
Inter Domes XXX

But i want

Sales Type Yesterda_Sales Month_sales
3rd Domes XXX XXX
3rd Export XXX XXX
Inter Domes XXX XXX

Current query is

select
ABAC29_DESC as Sales,ABAC30_DESC as Type , round(sum(order_qty*UNIT)/1000000,2) as MTD_Sales_Million from sales
where
datediff(month,invoice_date,getdate())<=0

request your help to include the yesterday sales also.

Thanks


Suresh.K.P

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2014-02-13 : 07:47:58
[code]select 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 YESTERDAY_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[/code]


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

jdeforums
Starting Member

8 Posts

Posted - 2014-02-15 : 02:02:07
quote:
Originally posted by khtan

select 	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 YESTERDAY_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



KH
[spoiler]Time is always against us[/spoiler]





Many Thanks KH.

Suresh.K.P
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2014-02-15 : 02:09:08
you are welcome


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page
   

- Advertisement -