Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 4

SELECT isd.

FiscalPeriodStartDate ,
isd.FinancialAccountId ,
isd.FinancialAccountName ,
isd.FinancialAccountSubGroupName ,
isd.FinancialAccountGroupName ,
isd.FinancialReportBlock ,
isd.FinancialCompanyId ,
isd.FinancialCompanyId_Rollup ,
isd.FinancialCompanyDescription_Rollup ,
CombCompanyRollup,
isd.FinancialCompanyDescription ,
isd.FinancialProductId ,
isd.FinancialProductDescription ,
isd.FinancialDepartmentId ,
isd.FinancialDepartmentDesc ,
isd.FinancialDepartmentGroupId ,
isd.FinancialDepartmentGroupDesc,
isd.FinancialDepartmentParentId ,
isd.FinancialDepartmentParentDesc ,
isd.SeniorVicePresidentName,
isd.RegionalVicePresidentName,
isd.LocationId,
isd.LocationName,
isd.LedgerId,
isd.Country,
','+ac.ALL_Roles_Username+',' as UserNames,
isd.CYMTD_Accounted_Amt,
isd.CYMTD_Budget_Amt,
isd.PYMTD_Accounted_Amt
FROM
(SELECT FiscalPeriodStartDate ,
FinancialAccountId ,
FinancialAccountName ,
FinancialAccountSubGroupName ,
FinancialAccountGroupName ,
FinancialReportBlock ,
FinancialCompanyId ,
FinancialCompanyId_Rollup ,
FinancialCompanyDescription_Rollup ,
CombCompanyRollup,
FinancialCompanyDescription ,
FinancialProductId ,
FinancialProductDescription ,
FinancialDepartmentId ,
FinancialDepartmentDesc ,
FinancialDepartmentGroupId ,
FinancialDepartmentGroupDesc,
FinancialDepartmentParentId ,
FinancialDepartmentParentDesc ,
SeniorVicePresidentName,
RegionalVicePresidentName,
LocationId,
LocationName,
LedgerId,
Country,
SUM(CYMTD_Accounted_Amt) CYMTD_Accounted_Amt,
SUM(CYMTD_Budget_Amt) CYMTD_Budget_Amt,
SUM(PYMTD_Accounted_Amt) PYMTD_Accounted_Amt
from
(SELECT FiscalPeriodStartDate ,
FinancialAccountId ,
FinancialAccountName ,
FinancialAccountSubGroupName ,
FinancialAccountGroupName ,
FinancialReportBlock ,
FinancialCompanyId ,
FinancialCompanyId_Rollup ,
FinancialCompanyDescription_Rollup ,
CombCompanyRollup,
FinancialCompanyDescription ,
FinancialProductId ,
FinancialProductDescription ,
FinancialDepartmentId ,
FinancialDepartmentDesc ,
FinancialDepartmentGroupId ,
FinancialDepartmentGroupDesc,
FinancialDepartmentParentId ,
FinancialDepartmentParentDesc ,
SeniorVicePresidentName,
RegionalVicePresidentName,
LocationId,
LocationName,
LedgerId,
CASE When ct.EDWCodeTypeDesc IS NULL then 'Canada' else ct.EDWCodeType end
Country,
CASE When LedgerId=1 then CYMTD_Entered_Amt else CYMTD_Accounted_Amt end
CYMTD_Accounted_Amt,
CASE When LedgerId=1 then CYMTD_Entered_Budget_Amt else CYMTD_Budget_Amt end
CYMTD_Budget_Amt,
0 PYMTD_Accounted_Amt

FROM dbo.MTHLY_GL_IncomeStatement_SVR_Details isd


LEFT JOIN [EDW_AnalyticsEDW].[dbo].[D_EDWCodeTypes] ct on
isd.FinancialCompanyId_Rollup=ct.EDWCodeTypeDesc
AND ct.EDWCodeCategory = 'domesticFilter' and ct.EDWCodeTypeExpDate = '2099-12-31'
and ct.EDWActiveRecordInd = 1
WHERE FinancialReportBlock in ('Revenue','COS','SGA')
AND FiscalPeriodStartDate >= '2015/01/01'
AND (LedgerID=62 or (LedgerID=1 and FinancialCompanyId_Rollup =
ct.EDWCodeTypeDesc))

UNION ALL

SELECT DATEADD(YEAR,1,FiscalPeriodStartDate) FiscalPeriodStartDate,


FinancialAccountId ,
FinancialAccountName ,
FinancialAccountSubGroupName ,
FinancialAccountGroupName ,
FinancialReportBlock ,
FinancialCompanyId ,
FinancialCompanyId_Rollup ,
FinancialCompanyDescription_Rollup ,
CombCompanyRollup,
FinancialCompanyDescription ,
FinancialProductId ,
FinancialProductDescription ,
FinancialDepartmentId ,
FinancialDepartmentDesc ,
FinancialDepartmentGroupId ,
FinancialDepartmentGroupDesc,
FinancialDepartmentParentId ,
FinancialDepartmentParentDesc ,
SeniorVicePresidentName,
RegionalVicePresidentName,
LocationId,
LocationName,
LedgerId,
CASE When ct.EDWCodeTypeDesc IS NULL then 'Canada' else ct.EDWCodeType end
Country,
0 CYMTD_Accounted_Amt,
0 CYMTD_Budget_Amt,
CASE When LedgerId=1 then CYMTD_Entered_Amt else CYMTD_Accounted_Amt end
PYMTD_Accounted_Amt

FROM dbo.MTHLY_GL_IncomeStatement_SVR_Details isd


LEFT JOIN [EDW_AnalyticsEDW].[dbo].[D_EDWCodeTypes] ct on
isd.FinancialCompanyId_Rollup=ct.EDWCodeTypeDesc
AND ct.EDWCodeCategory = 'domesticFilter' and ct.EDWCodeTypeExpDate = '2099-12-31'
and ct.EDWActiveRecordInd = 1
WHERE FinancialReportBlock in ('Revenue','COS','SGA')
AND YEAR(FiscalPeriodStartDate)+1<=Year(Getdate())
AND FiscalPeriodStartDate >= '2014/01/01'

AND
(LedgerID=62 or (LedgerID=1 and FinancialCompanyId_Rollup in( select
EDWCodeTypeDesc
FROM [EDW_AnalyticsEDW].[dbo].[D_EDWCodeTypes]
where EDWCodeCategory = 'domesticFilter' and EDWCodeTypeExpDate = '2099-12-
31' and EDWActiveRecordInd = 1)))
)A ---- for calana or mexico

GROUP BY FiscalPeriodStartDate ,
FinancialAccountId ,
FinancialAccountName ,
FinancialAccountSubGroupName ,
FinancialAccountGroupName ,
FinancialReportBlock ,
FinancialCompanyId ,
FinancialCompanyId_Rollup ,
FinancialCompanyDescription_Rollup ,
CombCompanyRollup,
FinancialCompanyDescription ,
FinancialProductId ,
FinancialProductDescription ,
FinancialDepartmentId ,
FinancialDepartmentDesc ,
FinancialDepartmentGroupId ,
FinancialDepartmentGroupDesc,
FinancialDepartmentParentId ,
FinancialDepartmentParentDesc ,
SeniorVicePresidentName,
RegionalVicePresidentName,
LocationId,
LocationName,
LedgerId,
Country)isd
left outer join EDW_AnalyticsEDW.dbo.F_Access_control ac
on isd.LocationId=ac.LocationId
and isd.FinancialDepartmentId=ac.FinancialDepartmentId
and isd.LedgerId=ac.LedgerId

You might also like