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 2008 Forums
 Transact-SQL (2008)
 Cumulative YTD Calculation

Author  Topic 

kond.mohan
Posting Yak Master

213 Posts

Posted - 2014-04-07 : 09:13:58
Dear all
i need to prepare the MTD and YTD Logic for my Reporting purpose using Sql server.
this is my query SELECT bsis.hkont GLCODE,
skat.TXT50 GLDESCRITPTION ,
GLMASTER.GROUP1,
GLMASTER.GROUP2,
GLMASTER.GROUP3,
GLMASTER.GROUP4,
bsis.PRCTR PROFITCTR,BSIS.SEGMENT ,
BSIS.BUDAT,
REPLACE(RIGHT(CONVERT(VARCHAR(9), BSIS.BUDAT, 6), 6), ' ', '-') DATE,
SUM(DMBTR) "ACTUALAMTRS IN LACS"
from bsis
inner join SKAT on bsis.hkont= skat.SAKNR
INNER JOIN GLMASTER ON GLMASTER.GLCODE=bsis.hkont

WHERE bsis.BUDAT between '2012-04-01' AND '2012-05-31'
--AND BSIS.HKONT IN ('0031037200')
GROUP BY BSIS.HKONT,bsis.hkont ,
skat.TXT50 ,BSIS.BUDAT,bsis.PRCTR ,BSIS.SEGMENT ,GLMASTER.GROUP1,
GLMASTER.GROUP2,GLMASTER.GROUP3,GLMASTER.GROUP4
i need one more column on SUM(DMBTR) this column for cumulative baed on date filed and

sqlsaga
Yak Posting Veteran

93 Posts

Posted - 2014-04-07 : 17:05:30
if you don't post any DDL or DML it would be difficult to analyze and give the right approach. See
http://sqlsaga.com/sql-server/how-to-calculate-running-totals-in-sql-server/

This article should be your starting point.

Visit www.sqlsaga.com for more t-sql code snippets and BI related how to articles.
Go to Top of Page
   

- Advertisement -