Hi, I am stuck on a query. Perhaps someone here can shed some light on a possible solution. I have a financial table which contains monthly transactions. I need to create YTD balances from this table. I am doing this by joining the table on itself to that for each month, all transactions are grouped from that month and all previous months. So simply, Jan, Jan+Feb, Jan+Feb+Mar, etc. I need this to be perpetual, so i cant code any date ranges within the query.
I think the issue is that for a month that does not contain transactions using the same "Dimensions" such as the account, the data no longer shows for that month. So if Account 1000 was in Jan but it was not in Feb, then my query drops off Account 1000 in the Feb result.
I have tried changing the join type but that does not seem to resolve it.
Here is a simplified version of the query. trying to keep the post short and to the point.
---------------------------------------------------------
SELECT
t1.AccountID,
t1.AFEID,
t1.CompanyID,
sum(t2.Amount)as AMOUNTMST,
t1.CostCenterID,
t1.CurrencyMstID,
t1.DatasetID,
t1.LegalEntityID,
t1.LocationID,
t1.PeriodID
FROM glsummary176 t1
INNER JOIN glsummary176 t2
ON t1.AccountID=t2.AccountID
AND t1.AFEID=t2.AFEID
AND t1.CompanyID=t2.CompanyID
AND t1.CostCenterID=t2.CostCenterID
AND t1.CurrencyMstID=t2.CurrencyMstID
AND t1.LegalEntityID=t2.LegalEntityID
AND t1.LocationID=t2.LocationID
AND t1.PeriodID >=t2.PeriodID
WHERE Left(t1.AccountID,1) IN (1,2,3)
GROUP BY
t1.AccountID,
t1.AFEID,
t1.CompanyID,
t1.CostCenterID,
t1.CurrencyMstID,
t1.DatasetID,
t1.LegalEntityID,
t1.LocationID,
t1.PeriodID
order by t1.periodid
--------------------------
Thanks in advance for any ideas.
Mike
I think the issue is that for a month that does not contain transactions using the same "Dimensions" such as the account, the data no longer shows for that month. So if Account 1000 was in Jan but it was not in Feb, then my query drops off Account 1000 in the Feb result.
I have tried changing the join type but that does not seem to resolve it.
Here is a simplified version of the query. trying to keep the post short and to the point.
---------------------------------------------------------
SELECT
t1.AccountID,
t1.AFEID,
t1.CompanyID,
sum(t2.Amount)as AMOUNTMST,
t1.CostCenterID,
t1.CurrencyMstID,
t1.DatasetID,
t1.LegalEntityID,
t1.LocationID,
t1.PeriodID
FROM glsummary176 t1
INNER JOIN glsummary176 t2
ON t1.AccountID=t2.AccountID
AND t1.AFEID=t2.AFEID
AND t1.CompanyID=t2.CompanyID
AND t1.CostCenterID=t2.CostCenterID
AND t1.CurrencyMstID=t2.CurrencyMstID
AND t1.LegalEntityID=t2.LegalEntityID
AND t1.LocationID=t2.LocationID
AND t1.PeriodID >=t2.PeriodID
WHERE Left(t1.AccountID,1) IN (1,2,3)
GROUP BY
t1.AccountID,
t1.AFEID,
t1.CompanyID,
t1.CostCenterID,
t1.CurrencyMstID,
t1.DatasetID,
t1.LegalEntityID,
t1.LocationID,
t1.PeriodID
order by t1.periodid
--------------------------
Thanks in advance for any ideas.
Mike