Topic: Weekly summation of fields for the 5-year-old period
All kind days!
I had a question such. I do two tables - I receive dates and the totals, about 1000 records.
I receive it "kindly such code:
DECLARE @Category_RentHouse INT = 3 DECLARE @Category_Parents INT = 5 DECLARE @Category_Salary INT = 9 DECLARE @TestDateStart DATE = ' 2012-01-01' DECLARE @TestDateFinish DATE = ' 2017-03-10' select JoinedDays, SUM (Cash_Usd) TotalMoney from ( select CAST (TransactionDate AS DATE) JoinedDays, CASE WHEN CategoryID = @Category_RentHouse THEN (TransactionAmount * (-1)) WHEN CategoryID = @Category_Parents THEN TransactionAmount WHEN CategoryID = @Category_Salary THEN CAST ((TransactionAmount / RateValue) AS MONEY) ELSE CAST ((TransactionAmount * (-1) / RateValue) AS MONEY) END AS Cash_Usd FROM (select * from Marathon.dbo. Transactions T LEFT JOIN IntermediateM.dbo. Rates R ON T.TransactionDate = R.RateDate) Y ) RR WHERE JoinedDays BETWEEN @TestDateStart AND @TestDateFinish GROUP BY JoinedDays ORDER BY JoinedDays
And a question such - I need to deduce instead the total for each 7 days during 5 summer periods all it.
Some variants - the closest tried - add , but only for one 2012. And all. And it is necessary for the full period.