Académique Documents
Professionnel Documents
Culture Documents
as
select
SUB_R,New_SUB_R,Market,
'ACT' TYP,
'F' REC_TYP,
sum(GROSS_YTD_USD_R) GROSS_YTD_USD_SUMMRY,
sum(GROSS_YTD_R)GROSS_YTD_SUMMRY,
sum(GROSS_PYTD_USD_R)GROSS_PYTD_USD_SUMMRY,
sum(GROSS_PYTD_R)GROSS_PYTD_SUMMRY,
sum(GROSS_MTD_USD_R)GROSS_MTD_USD_SUMMRY,
SUM(GROSS_MTD_R)GROSS_MTD_SUMMRY,
sum(GROSS_PMTD_USD_R)GROSS_PMTD_USD_SUMMRY,
sum(GROSS_PMTD_R)GROSS_PMTD_SUMMRY,
sum(GROSS_PQTD_USD_R) GROSS_PQTD_USD_SUMMRY,
sum(GROSS_PQTD_R)GROSS_PQTD_SUMMRY,
sum(GROSS_QTD_USD_R)GROSS_QTD_USD_SUMMRY,
sum(GROSS_QTD_R)GROSS_QTD_SUMMRY,
0 PPR_YTD_USD_SUMMRY,
0 PPR_QTD_USD_SUMMRY,
0 PPR_MTD_USD_SUMMRY,
0 PPR_YTD_SUMMRY,
0 PPR_QTD_SUMMRY,
0 PPR_MTD_SUMMRY
from [dbo].[IGDW_SUMMARY_FACT] where SUB_R <> 'TotalDomestic-US'
group by SUB_R,New_SUB_R,Market
union all
select SUB_R,New_SUB_R,Market,
TYP,
REC_TYP,
GROSS_YTD_USD_SUMMRY,
GROSS_YTD_SUMMRY,
GROSS_PYTD_USD_SUMMRY,
GROSS_PYTD_SUMMRY,
GROSS_MTD_USD_SUMMRY,
GROSS_MTD_SUMMRY,
GROSS_PMTD_USD_SUMMRY,
GROSS_PMTD_SUMMRY,
GROSS_PQTD_USD_SUMMRY,
GROSS_PQTD_SUMMRY,
GROSS_QTD_USD_SUMMRY,
GROSS_QTD_SUMMRY,
PPR_YTD_USD_SUMMRY,
PPR_QTD_USD_SUMMRY,
PPR_MTD_USD_SUMMRY,
PPR_YTD_SUMMRY,
PPR_QTD_SUMMRY,
PPR_MTD_SUMMRY from BPC_PLN_SUMM_F_VV
MTD = 'Y'
then GROSS_SALE else 0 end) PPR_MTD_R,
-- This is for PYMTD
sum(Case when TYP = 'ACT' and REC_TYP in ('F','B') and
PriorMTD = 'Y'
then GROSS_USD else 0 end) GROSS_PMTD_USD_R,
sum(Case when TYP = 'ACT' and REC_TYP in ('F','B') and
PriorMTD = 'Y'
then GROSS_SALE else 0 end) GROSS_PMTD_R,
-- This needs to be changed when we get latest PPR switch
sum(Case when TYP = 'PPR10' and REC_TYP = ('P') and
PriorMTD = 'Y'
then GROSS_USD else 0 end) PPR_PMTD_USD_R,
sum(Case when TYP = 'PPR10' and REC_TYP = ('P') and
PriorMTD = 'Y'
then GROSS_SALE else 0 end) PPR_PMTD_R,
-- This is PriorQTD
sum(Case when TYP = 'ACT' and REC_TYP in ('F','B') and
PriorQTD = 'Y'
then GROSS_USD else 0 end) GROSS_PQTD_USD_R,
sum(Case when TYP = 'ACT' and REC_TYP in ('F','B') and
PriorQTD = 'Y'
then GROSS_SALE else 0 end) GROSS_PQTD_R,
-- This needs to be changed when we get latest PPR switch
sum(Case when TYP = 'PPR10' and REC_TYP = ('P') and
PriorQTD = 'Y'
then GROSS_USD else 0 end) PPR_PQTD_USD_R,
sum(Case when TYP = 'PPR10' and REC_TYP = ('P') and
PriorQTD = 'Y'
then GROSS_SALE else 0 end) PPR_PQTD_R,
-- This is QTD
sum(Case when TYP = 'ACT' and REC_TYP in ('F','B') and
QTD = 'Y'
then GROSS_USD else 0 end) GROSS_QTD_USD_R,
sum(Case when TYP = 'ACT' and REC_TYP in ('F','B') and
QTD = 'Y'
then GROSS_SALE else 0 end) GROSS_QTD_R,
-- This needs to be changed when we get latest PPR switch
sum(Case when TYP = 'PPR10' and REC_TYP = ('P') and
QTD = 'Y'
then GROSS_USD else 0 end) PPR_QTD_USD_R,
sum(Case when TYP = 'PPR10' and REC_TYP = ('P') and
QTD = 'Y'
-- This is QTD
sum(Case when TYP = 'ACT' and REC_TYP in ('F','B') and
QTD = 'Y'
then GROSS_USD else 0 end) GROSS_QTD_USD_R,
sum(Case when TYP = 'ACT' and REC_TYP in ('F','B') and
QTD = 'Y'
then GROSS_SALE else 0 end) GROSS_QTD_R,
-- This needs to be changed when we get latest PPR switch
sum(Case when TYP = 'PPR10' and REC_TYP = ('P') and
QTD = 'Y'
then GROSS_USD else 0 end) PPR_QTD_USD_R,
sum(Case when TYP = 'PPR10' and REC_TYP = ('P') and
QTD = 'Y'
then GROSS_SALE else 0 end) PPR_QTD_R
from IGDW_DAILYSALE_GLOBAL_FACT F left outer join
[dbo].[IGDW_REGION_D] R ON F.SALES_ORG = R.SALESORG
left outer join [dbo].[IGDW_DIST_CHNL_D] C ON C.DISTR_CHAN= F.DIST_CHNL
left outer join [dbo].[IGDW_MATERIAL_D] M ON M.MATERIAL = F.MATERIAL
left outer join [dbo].[IGDW_CUSTOMER_D] CS ON CS.CUSTOMER = F.SOLD_TO
left outer join [dbo].[IGDW_CAL_D] D ON D.Date = F.POST_DT
where MARKET <> 'BPC' and CHNL_DESC = 'EXPORT'
group by MARKET,M.SEGMENT,
M.Brand_USE,
M.BRANDGROUP,
SUB_REG,
GLOBAL_REG,
CUST_GRP,UOM
union all
-- ******This is Total Export*********----select SUB_REG SUB_REG_R,
GLOBAL_REG GLOBAL_REG_R,CUST_GRP CUST_GRP_R,UOM CURR, M.SEGMENT SEGMENT_R,
M.Brand_USE Brand_USE_R,
M.BRANDGROUP BRANDGROUP_R, 'TotalExport' SUB_R,
Space(40-Len('Total Export')) + 'Total Export' as New_SUB_R,
'Total Export ' as Market,
-- This is YTD
sum(Case when TYP = 'ACT' and REC_TYP in ('F','B') and
YTD = 'Y'
then GROSS_USD else 0 end) GROSS_YTD_USD_R,
sum(Case when TYP = 'ACT' and REC_TYP in ('F','B') and
YTD = 'Y'
then GROSS_SALE else 0 end) GROSS_YTD_R,
-- This needs to be changed when we get latest PPR switch
sum(Case when TYP = 'PPR10' and REC_TYP = ('P') and
YTD = 'Y'
then GROSS_USD else 0 end) PPR_YTD_USD_R,
sum(Case when TYP = 'PPR10' and REC_TYP = ('P') and
YTD = 'Y'
union all
-- ******This is Total 'DOMESTIC'*********----select SUB_REG SUB_REG_R,
group by M.SEGMENT,
M.Brand_USE,
M.BRANDGROUP,
SUB_REG,
GLOBAL_REG,
CUST_GRP,UOM
union all
-- ******This is TotalInternatioanl(Domestic+Export) '*********----select SUB_REG SUB_REG_R,
GLOBAL_REG GLOBAL_REG_R,CUST_GRP CUST_GRP_R,UOM CURR, M.SEGMENT SEGMENT_R,
M.Brand_USE Brand_USE_R,
M.BRANDGROUP BRANDGROUP_R, 'TotalInternational' SUB_R,
Space(40-Len('Total International')) + 'Total International' as New_SUB_R,
'Total International' as Market,
-- This is YTD
sum(Case when TYP = 'ACT' and REC_TYP in ('F','B') and
YTD = 'Y'
then GROSS_USD else 0 end) GROSS_YTD_USD_R,
sum(Case when TYP = 'ACT' and REC_TYP in ('F','B') and
YTD = 'Y'
then GROSS_SALE else 0 end) GROSS_YTD_R,
-- This needs to be changed when we get latest PPR switch
sum(Case when TYP = 'PPR10' and REC_TYP = ('P') and
YTD = 'Y'
then GROSS_USD else 0 end) PPR_YTD_USD_R,
sum(Case when TYP = 'PPR10' and REC_TYP = ('P') and
YTD = 'Y'
then GROSS_SALE else 0 end) PPR_YTD_R,
-- This is PYTD
sum(Case when TYP = 'ACT' and REC_TYP in ('F','B') and
PriorYTD = 'Y'
then GROSS_USD else 0 end) GROSS_PYTD_USD_R,
sum(Case when TYP = 'ACT' and REC_TYP in ('F','B') and
PriorYTD = 'Y'
then GROSS_SALE else 0 end) GROSS_PYTD_R,
-- This needs to be changed when we get latest PPR switch
sum(Case when TYP = 'PPR10' and REC_TYP = ('P') and
PriorYTD = 'Y'
then GROSS_USD else 0 end) PPR_PYTD_USD_R,
sum(Case when TYP = 'PPR10' and REC_TYP = ('P') and
PriorYTD = 'Y'
then GROSS_SALE else 0 end) PPR_PYTD_R,
-- This is for MTD
union all
-- ******This is TotalEurope(Domestic) '*********----select SUB_REG SUB_REG_R,
GLOBAL_REG GLOBAL_REG_R,CUST_GRP CUST_GRP_R,UOM CURR, M.SEGMENT SEGMENT_R,
M.Brand_USE Brand_USE_R,
M.BRANDGROUP BRANDGROUP_R, 'TotalEuropeDomestic' SUB_R,
Space(40-Len('Total Europe Domestic')) + 'Total Europe Domestic' as New_SUB_R,
'Total Europe Domestic' as Market,
-- This is YTD
sum(Case when TYP = 'ACT' and REC_TYP in ('F','B') and
YTD = 'Y'
then GROSS_USD else 0 end) GROSS_YTD_USD_R,
sum(Case when TYP = 'ACT' and REC_TYP in ('F','B') and
YTD = 'Y'
then GROSS_SALE else 0 end) GROSS_YTD_R,
-- This needs to be changed when we get latest PPR switch
sum(Case when TYP = 'PPR10' and REC_TYP = ('P') and
YTD = 'Y'
then GROSS_USD else 0 end) PPR_YTD_USD_R,
sum(Case when TYP = 'PPR10' and REC_TYP = ('P') and
YTD = 'Y'
then GROSS_SALE else 0 end) PPR_YTD_R,
-- This is PYTD
sum(Case when TYP = 'ACT' and REC_TYP in ('F','B') and
PriorYTD = 'Y'
then GROSS_USD else 0 end) GROSS_PYTD_USD_R,
sum(Case when TYP = 'ACT' and REC_TYP in ('F','B') and
PriorYTD = 'Y'
then GROSS_SALE else 0 end) GROSS_PYTD_R,
-- This needs to be changed when we get latest PPR switch
sum(Case when TYP = 'PPR10' and REC_TYP = ('P') and
PriorYTD = 'Y'
then GROSS_USD else 0 end) PPR_PYTD_USD_R,
sum(Case when TYP = 'PPR10' and REC_TYP = ('P') and
PriorYTD = 'Y'
then GROSS_SALE else 0 end) PPR_PYTD_R,
-- This is for MTD
sum(Case when TYP = 'ACT' and REC_TYP in ('F','B') and
MTD = 'Y'
then GROSS_USD else 0 end) GROSS_MTD_USD_R,
sum(Case when TYP = 'ACT' and REC_TYP in ('F','B') and
MTD = 'Y'
then GROSS_SALE else 0 end) GROSS_MTD_R,
-- This needs to be changed when we get latest PPR switch
sum(Case when TYP = 'PPR10' and REC_TYP = ('P') and
MTD = 'Y'
then GROSS_USD else 0 end) PPR_MTD_USD_R,
sum(Case when TYP = 'PPR10' and REC_TYP = ('P') and
MTD = 'Y'
then GROSS_SALE else 0 end) PPR_MTD_R,
-- This is for PYMTD
sum(Case when TYP = 'ACT' and REC_TYP in ('F','B') and
PriorMTD = 'Y'
then GROSS_USD else 0 end) GROSS_PMTD_USD_R,
sum(Case when TYP = 'ACT' and REC_TYP in ('F','B') and
PriorMTD = 'Y'
then GROSS_SALE else 0 end) GROSS_PMTD_R,
-- This needs to be changed when we get latest PPR switch
sum(Case when TYP = 'PPR10' and REC_TYP = ('P') and
PriorMTD = 'Y'
then GROSS_USD else 0 end) PPR_PMTD_USD_R,
sum(Case when TYP = 'PPR10' and REC_TYP = ('P') and
PriorMTD = 'Y'
then GROSS_SALE else 0 end) PPR_PMTD_R,
-- This is PriorQTD
union all
-- ******This is TotalEurope(Export) '*********----select SUB_REG SUB_REG_R,
GLOBAL_REG GLOBAL_REG_R,CUST_GRP CUST_GRP_R, UOM CURR, M.SEGMENT SEGMENT_R,
M.Brand_USE Brand_USE_R,
M.BRANDGROUP BRANDGROUP_R, 'TotalEuropeExport' SUB_R,
PriorYTD = 'Y'
then GROSS_USD else 0 end) GROSS_PYTD_USD_R,
sum(Case when TYP = 'ACT' and REC_TYP in ('F','B') and
PriorYTD = 'Y'
then GROSS_SALE else 0 end) GROSS_PYTD_R,
-- This needs to be changed when we get latest PPR switch
sum(Case when TYP = 'PPR10' and REC_TYP = ('P') and
PriorYTD = 'Y'
then GROSS_USD else 0 end) PPR_PYTD_USD_R,
sum(Case when TYP = 'PPR10' and REC_TYP = ('P') and
PriorYTD = 'Y'
then GROSS_SALE else 0 end) PPR_PYTD_R,
-- This is for MTD
sum(Case when TYP = 'ACT' and REC_TYP in ('F','B') and
MTD = 'Y'
then GROSS_USD else 0 end) GROSS_MTD_USD_R,
sum(Case when TYP = 'ACT' and REC_TYP in ('F','B') and
MTD = 'Y'
then GROSS_SALE else 0 end) GROSS_MTD_R,
-- This needs to be changed when we get latest PPR switch
sum(Case when TYP = 'PPR10' and REC_TYP = ('P') and
MTD = 'Y'
then GROSS_USD else 0 end) PPR_MTD_USD_R,
sum(Case when TYP = 'PPR10' and REC_TYP = ('P') and
MTD = 'Y'
then GROSS_SALE else 0 end) PPR_MTD_R,
-- This is for PYMTD
sum(Case when TYP = 'ACT' and REC_TYP in ('F','B') and
PriorMTD = 'Y'
then GROSS_USD else 0 end) GROSS_PMTD_USD_R,
sum(Case when TYP = 'ACT' and REC_TYP in ('F','B') and
PriorMTD = 'Y'
then GROSS_SALE else 0 end) GROSS_PMTD_R,
-- This needs to be changed when we get latest PPR switch
sum(Case when TYP = 'PPR10' and REC_TYP = ('P') and
PriorMTD = 'Y'
then GROSS_USD else 0 end) PPR_PMTD_USD_R,
sum(Case when TYP = 'PPR10' and REC_TYP = ('P') and
PriorMTD = 'Y'
then GROSS_SALE else 0 end) PPR_PMTD_R,
-- This is PriorQTD
sum(Case when TYP = 'ACT' and REC_TYP in ('F','B') and
PriorQTD = 'Y'
then GROSS_USD else 0 end) GROSS_PQTD_USD_R,
0 GROSS_YTD_USD_SUMMRY,
0 GROSS_YTD_SUMMRY,
0 GROSS_PYTD_USD_SUMMRY,
0 GROSS_PYTD_SUMMRY,
0 GROSS_MTD_USD_SUMMRY,
0 GROSS_MTD_SUMMRY,
0 GROSS_PMTD_USD_SUMMRY,
0 GROSS_PMTD_SUMMRY,
0 GROSS_PQTD_USD_SUMMRY,
0 GROSS_PQTD_SUMMRY,
0 GROSS_QTD_USD_SUMMRY,
0 GROSS_QTD_SUMMRY,
sum(case when month(Plan_date) <= month(getdate()) then PPR_PLN * SIGNEDDATA els
e 0 end) PPR_YTD_USD_SUMMRY,
sum(case when datepart(q,Plan_date) = datepart (q,getdate()) then PPR_PLN * SIGN
EDDATA else 0 end) PPR_QTD_USD_SUMMRY,
sum(case when month(Plan_date) = Month(getdate()) then PPR_PLN * SIGNEDDATA else
0 end) PPR_MTD_USD_SUMMRY,
sum(case when month(Plan_date) <= month(getdate()) then PPR_PLN else 0 end) PPR
_YTD_SUMMRY,
sum(case when datepart(q,Plan_date) = datepart (q,getdate()) then PPR_PLN else
0 end) PPR_QTD_SUMMRY,
sum(case when month(Plan_date) = Month(getdate()) then PPR_PLN else 0 end) PPR_M
TD_SUMMRY
from BPC_SUMMAR_PPRPLAN_VV P left outer join [dbo].[BPC_RATES] B ON
B.CATEGORY = P.PPRTYP and YEAR (Plan_date) *100 + Month (Plan_date) = substring
(B.TIMEID,1,4) *100 + substring(B.TIMEID,5,2) and
P.CURR = B.INPUTCURRENCY
where P.CHANNEL = 'Domestic'
group by PPRTYP
union all
-- This is for Domestic for each sub...
select
'TotalDomestic-'+ P."SOURCE" SUB_R,
Space(40-Len('Total Domestic -'+ Ltrim(Rtrim(P."SOURCE")))) + 'Total Domestic -'
+ Ltrim(Rtrim(P."SOURCE")) as New_SUB_R,
'Total Domestic -' + Ltrim(Rtrim(P."SOURCE")) as Market,
PPRTYP TYP,
'X' REC_TYP,
0 GROSS_YTD_USD_SUMMRY,
0 GROSS_YTD_SUMMRY,
0 GROSS_PYTD_USD_SUMMRY,
0 GROSS_PYTD_SUMMRY,
0 GROSS_MTD_USD_SUMMRY,
0 GROSS_MTD_SUMMRY,
0 GROSS_PMTD_USD_SUMMRY,
0 GROSS_PMTD_SUMMRY,
0 GROSS_PQTD_USD_SUMMRY,
0 GROSS_PQTD_SUMMRY,
0 GROSS_QTD_USD_SUMMRY,
0 GROSS_QTD_SUMMRY,
sum(case when month(Plan_date) <= month(getdate()) then PPR_PLN * SIGNEDDATA els
e 0 end) PPR_YTD_USD_SUMMRY,
sum(case when datepart(q,Plan_date) = datepart (q,getdate()) then PPR_PLN * SIGN
EDDATA else 0 end) PPR_QTD_USD_SUMMRY,
union all
-- This is for Domestic europe...
select
'TotalEuropeDomestic' SUB_R,
Space(40-Len('Total Europe Domestic')) + 'Total Europe Domestic' as New_SUB_R,
'Total Europe Domestic' as Market,
PPRTYP TYP,
'X' REC_TYP,
0 GROSS_YTD_USD_SUMMRY,
0 GROSS_YTD_SUMMRY,
0 GROSS_PYTD_USD_SUMMRY,
0 GROSS_PYTD_SUMMRY,
0 GROSS_MTD_USD_SUMMRY,
0 GROSS_MTD_SUMMRY,
0 GROSS_PMTD_USD_SUMMRY,
0 GROSS_PMTD_SUMMRY,
0 GROSS_PQTD_USD_SUMMRY,
0 GROSS_PQTD_SUMMRY,
0 GROSS_QTD_USD_SUMMRY,
0 GROSS_QTD_SUMMRY,
sum(case when month(Plan_date) <= month(getdate()) then PPR_PLN * SIGNEDDATA els
e 0 end) PPR_YTD_USD_SUMMRY,
sum(case when datepart(q,Plan_date) = datepart (q,getdate()) then PPR_PLN * SIGN
EDDATA else 0 end) PPR_QTD_USD_SUMMRY,
sum(case when month(Plan_date) = Month(getdate()) then PPR_PLN * SIGNEDDATA else
0 end) PPR_MTD_USD_SUMMRY,
sum(case when month(Plan_date) <= month(getdate()) then PPR_PLN else 0 end) PPR
_YTD_SUMMRY,
sum(case when datepart(q,Plan_date) = datepart (q,getdate()) then PPR_PLN else
0 end) PPR_QTD_SUMMRY,
sum(case when month(Plan_date) = Month(getdate()) then PPR_PLN else 0 end) PPR_M
TD_SUMMRY
from BPC_SUMMAR_PPRPLAN_VV P left outer join [dbo].[BPC_RATES] B ON
B.CATEGORY = P.PPRTYP and YEAR (Plan_date) *100 + Month (Plan_date) = substring
(B.TIMEID,1,4) *100 + substring(B.TIMEID,5,2) and
P.CURR = B.INPUTCURRENCY
where P.CHANNEL = 'Domestic' and
P."SOURCE" in ('FR','UK')
group by PPRTYP
union all
-- This is for export europe...
select
'TotalEuropeExport' SUB_R,
Space(40-Len('Total Europe Export')) + 'Total Europe Export' as New_SUB_R,
'Total Europe Export' as Market,
PPRTYP TYP,
'X' REC_TYP,
0 GROSS_YTD_USD_SUMMRY,
0 GROSS_YTD_SUMMRY,
0 GROSS_PYTD_USD_SUMMRY,
0 GROSS_PYTD_SUMMRY,
0 GROSS_MTD_USD_SUMMRY,
0 GROSS_MTD_SUMMRY,
0 GROSS_PMTD_USD_SUMMRY,
0 GROSS_PMTD_SUMMRY,
0 GROSS_PQTD_USD_SUMMRY,
0 GROSS_PQTD_SUMMRY,
0 GROSS_QTD_USD_SUMMRY,
0 GROSS_QTD_SUMMRY,
sum(case when month(Plan_date) <= month(getdate()) then PPR_PLN * SIGNEDDATA els
e 0 end) PPR_YTD_USD_SUMMRY,
sum(case when datepart(q,Plan_date) = datepart (q,getdate()) then PPR_PLN * SIGN
EDDATA else 0 end) PPR_QTD_USD_SUMMRY,
sum(case when month(Plan_date) = Month(getdate()) then PPR_PLN * SIGNEDDATA else
0 end) PPR_MTD_USD_SUMMRY,
sum(case when month(Plan_date) <= month(getdate()) then PPR_PLN else 0 end) PPR
_YTD_SUMMRY,
sum(case when datepart(q,Plan_date) = datepart (q,getdate()) then PPR_PLN else
0 end) PPR_QTD_SUMMRY,
sum(case when month(Plan_date) = Month(getdate()) then PPR_PLN else 0 end) PPR_M
TD_SUMMRY
from BPC_SUMMAR_PPRPLAN_VV P left outer join [dbo].[BPC_RATES] B ON
B.CATEGORY = P.PPRTYP and YEAR (Plan_date) *100 + Month (Plan_date) = substring
(B.TIMEID,1,4) *100 + substring(B.TIMEID,5,2) and
P.CURR = B.INPUTCURRENCY
where P.CHANNEL = 'Export' and
P."SOURCE" in ('FR','UK')
group by PPRTYP
union all
-- This is for export europe...
select
'TotalExport' SUB_R,
Space(40-Len('Total Export')) + 'Total Export' as New_SUB_R,
'Total Export' as Market,
PPRTYP TYP,
'X' REC_TYP,
0 GROSS_YTD_USD_SUMMRY,
0 GROSS_YTD_SUMMRY,
0 GROSS_PYTD_USD_SUMMRY,
0 GROSS_PYTD_SUMMRY,
0 GROSS_MTD_USD_SUMMRY,
0 GROSS_MTD_SUMMRY,
0 GROSS_PMTD_USD_SUMMRY,
0 GROSS_PMTD_SUMMRY,
0 GROSS_PQTD_USD_SUMMRY,
0 GROSS_PQTD_SUMMRY,
0 GROSS_QTD_USD_SUMMRY,
0 GROSS_QTD_SUMMRY,
sum(case when month(Plan_date) <= month(getdate()) then PPR_PLN * SIGNEDDATA els
e 0 end) PPR_YTD_USD_SUMMRY,
sum(case when datepart(q,Plan_date) = datepart (q,getdate()) then PPR_PLN * SIGN
EDDATA else 0 end) PPR_QTD_USD_SUMMRY,
sum(case when month(Plan_date) = Month(getdate()) then PPR_PLN * SIGNEDDATA else
0 end) PPR_MTD_USD_SUMMRY,
sum(case when month(Plan_date) <= month(getdate()) then PPR_PLN else 0 end) PPR
_YTD_SUMMRY,
sum(case when datepart(q,Plan_date) = datepart (q,getdate()) then PPR_PLN else
0 end) PPR_QTD_SUMMRY,
sum(case when month(Plan_date) = Month(getdate()) then PPR_PLN else 0 end) PPR_M
TD_SUMMRY
from BPC_SUMMAR_PPRPLAN_VV P left outer join [dbo].[BPC_RATES] B ON
B.CATEGORY = P.PPRTYP and YEAR (Plan_date) *100 + Month (Plan_date) = substring
(B.TIMEID,1,4) *100 + substring(B.TIMEID,5,2) and
P.CURR = B.INPUTCURRENCY
where P.CHANNEL = 'Export'
group by PPRTYP
union all
-- This is for Export for each sub...
select
'TotalExport-'+ P."SOURCE" SUB_R,
Space(40-Len('Total Export -'+ Ltrim(Rtrim(P."SOURCE")))) + 'Total Export -'+ Lt
rim(Rtrim(P."SOURCE")) as New_SUB_R,
'Total Export -'+ Ltrim(Rtrim(P."SOURCE")) as Market,
PPRTYP TYP,
'X' REC_TYP,
0 GROSS_YTD_USD_SUMMRY,
0 GROSS_YTD_SUMMRY,
0 GROSS_PYTD_USD_SUMMRY,
0 GROSS_PYTD_SUMMRY,
0 GROSS_MTD_USD_SUMMRY,
0 GROSS_MTD_SUMMRY,
0 GROSS_PMTD_USD_SUMMRY,
0 GROSS_PMTD_SUMMRY,
0 GROSS_PQTD_USD_SUMMRY,
0 GROSS_PQTD_SUMMRY,
0 GROSS_QTD_USD_SUMMRY,
0 GROSS_QTD_SUMMRY,
sum(case when month(Plan_date) <= month(getdate()) then PPR_PLN * SIGNEDDATA els
e 0 end) PPR_YTD_USD_SUMMRY,
sum(case when datepart(q,Plan_date) = datepart (q,getdate()) then PPR_PLN * SIGN
EDDATA else 0 end) PPR_QTD_USD_SUMMRY,
sum(case when month(Plan_date) = Month(getdate()) then PPR_PLN * SIGNEDDATA else
0 end) PPR_MTD_USD_SUMMRY,
sum(case when month(Plan_date) <= month(getdate()) then PPR_PLN else 0 end) PPR
_YTD_SUMMRY,
select
'TotalInterEurope' SUB_R,
Space(40-Len('Total International Europe')) + 'Total International Europe' as Ne
w_SUB_R,
'Total International Europe' as Market,
PPRTYP TYP,
'X' REC_TYP,
0 GROSS_YTD_USD_SUMMRY,
0 GROSS_YTD_SUMMRY,
0 GROSS_PYTD_USD_SUMMRY,
0 GROSS_PYTD_SUMMRY,
0 GROSS_MTD_USD_SUMMRY,
0 GROSS_MTD_SUMMRY,
0 GROSS_PMTD_USD_SUMMRY,
0 GROSS_PMTD_SUMMRY,
0 GROSS_PQTD_USD_SUMMRY,
0 GROSS_PQTD_SUMMRY,
0 GROSS_QTD_USD_SUMMRY,
0 GROSS_QTD_SUMMRY,
sum(case when month(Plan_date) <= month(getdate()) then PPR_PLN * SIGNEDDATA els
e 0 end) PPR_YTD_USD_SUMMRY,
sum(case when datepart(q,Plan_date) = datepart (q,getdate()) then PPR_PLN * SIGN
EDDATA else 0 end) PPR_QTD_USD_SUMMRY,
sum(case when month(Plan_date) = Month(getdate()) then PPR_PLN * SIGNEDDATA else
0 end) PPR_MTD_USD_SUMMRY,
sum(case when month(Plan_date) <= month(getdate()) then PPR_PLN else 0 end) PPR
_YTD_SUMMRY,
sum(case when datepart(q,Plan_date) = datepart (q,getdate()) then PPR_PLN else
0 end) PPR_QTD_SUMMRY,
sum(case when month(Plan_date) = Month(getdate()) then PPR_PLN else 0 end) PPR_M
TD_SUMMRY
from BPC_SUMMAR_PPRPLAN_VV P left outer join [dbo].[BPC_RATES] B ON
B.CATEGORY = P.PPRTYP and YEAR (Plan_date) *100 + Month (Plan_date) = substring
(B.TIMEID,1,4) *100 + substring(B.TIMEID,5,2) and
P.CURR = B.INPUTCURRENCY
where P.CHANNEL in('Domestic', 'Export') and P."SOURCE" in ('UK','FR')
group by PPRTYP
union all
-- This is total international for each sub...
select
'TotalInternational' SUB_R,
Space(40-Len('Total International')) + 'Total International' as New_SUB_R,
'Total International' as Market,
PPRTYP TYP,
'X' REC_TYP,
0 GROSS_YTD_USD_SUMMRY,
0 GROSS_YTD_SUMMRY,
0 GROSS_PYTD_USD_SUMMRY,
0 GROSS_PYTD_SUMMRY,
0 GROSS_MTD_USD_SUMMRY,
0 GROSS_MTD_SUMMRY,
0 GROSS_PMTD_USD_SUMMRY,
0 GROSS_PMTD_SUMMRY,
0 GROSS_PQTD_USD_SUMMRY,
0 GROSS_PQTD_SUMMRY,
0 GROSS_QTD_USD_SUMMRY,
0 GROSS_QTD_SUMMRY,
sum(case when month(Plan_date) <= month(getdate()) then PPR_PLN * SIGNEDDATA els
e 0 end) PPR_YTD_USD_SUMMRY,
sum(case when datepart(q,Plan_date) = datepart (q,getdate()) then PPR_PLN * SIGN
EDDATA else 0 end) PPR_QTD_USD_SUMMRY,
sum(case when month(Plan_date) = Month(getdate()) then PPR_PLN * SIGNEDDATA else
0 end) PPR_MTD_USD_SUMMRY,
sum(case when month(Plan_date) <= month(getdate()) then PPR_PLN else 0 end) PPR
_YTD_SUMMRY,
sum(case when datepart(q,Plan_date) = datepart (q,getdate()) then PPR_PLN else
0 end) PPR_QTD_SUMMRY,
sum(case when month(Plan_date) = Month(getdate()) then PPR_PLN else 0 end) PPR_M
TD_SUMMRY
from BPC_SUMMAR_PPRPLAN_VV P left outer join [dbo].[BPC_RATES] B ON
B.CATEGORY = P.PPRTYP and YEAR (Plan_date) *100 + Month (Plan_date) = substring
(B.TIMEID,1,4) *100 + substring(B.TIMEID,5,2) and
P.CURR = B.INPUTCURRENCY
where P.CHANNEL in('Domestic', 'Export')
group by PPRTYP