1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
| SELECT dbo.[Dim Company].GKA,
[ZIG Number],
[Country Code],
[Reporting Line],
CASE WHEN left([Proposal Type],3)='New' then 'New Proposal'
WHEN left([Proposal Type],3)='Ren' then 'Renewal' else null end as [Type],
CASE WHEN LEFT([Proposal Status], 3) >= '020' THEN 'Issued' ELSE NULL END AS [Status],
YEAR([Issuing Date]) AS Year,
Case when MONTH([Issuing Date])=1 then count(*) else 0 end as [Nb1],
Case when MONTH([Issuing Date])=2 then count(*) else 0 end as [Nb2],
Case when MONTH([Issuing Date])=3 then count(*) else 0 end as [Nb3],
Case when MONTH([Issuing Date])=4 then count(*) else 0 end as [Nb4],
Case when MONTH([Issuing Date])=5 then count(*) else 0 end as [Nb5],
Case when MONTH([Issuing Date])=6 then count(*) else 0 end as [Nb6],
Case when MONTH([Issuing Date])=7 then count(*) else 0 end as [Nb7],
Case when MONTH([Issuing Date])=8 then count(*) else 0 end as [Nb8],
Case when MONTH([Issuing Date])=9 then count(*) else 0 end as [Nb9],
Case when MONTH([Issuing Date])=10 then count(*) else 0 end as [Nb10],
Case when MONTH([Issuing Date])=11 then count(*) else 0 end as [Nb11],
Case when MONTH([Issuing Date])=12 then count(*) else 0 end as [Nb12],
Case when MONTH([Issuing Date])=1 then sum(dbo.[Fact Proposal].[Proposal Amount (Euro)]) else 0 end as [Amount1],
Case when MONTH([Issuing Date])=2 then sum(dbo.[Fact Proposal].[Proposal Amount (Euro)]) else 0 end as [Amount2],
Case when MONTH([Issuing Date])=3 then sum(dbo.[Fact Proposal].[Proposal Amount (Euro)]) else 0 end as [Amount3],
Case when MONTH([Issuing Date])=4 then sum(dbo.[Fact Proposal].[Proposal Amount (Euro)]) else 0 end as [Amount4],
Case when MONTH([Issuing Date])=5 then sum(dbo.[Fact Proposal].[Proposal Amount (Euro)]) else 0 end as [Amount5],
Case when MONTH([Issuing Date])=6 then sum(dbo.[Fact Proposal].[Proposal Amount (Euro)]) else 0 end as [Amount6],
Case when MONTH([Issuing Date])=7 then sum(dbo.[Fact Proposal].[Proposal Amount (Euro)]) else 0 end as [Amount7],
Case when MONTH([Issuing Date])=8 then sum(dbo.[Fact Proposal].[Proposal Amount (Euro)]) else 0 end as [Amount8],
Case when MONTH([Issuing Date])=9 then sum(dbo.[Fact Proposal].[Proposal Amount (Euro)]) else 0 end as [Amount9],
Case when MONTH([Issuing Date])=10 then sum(dbo.[Fact Proposal].[Proposal Amount (Euro)]) else 0 end as [Amount10],
Case when MONTH([Issuing Date])=11 then sum(dbo.[Fact Proposal].[Proposal Amount (Euro)]) else 0 end as [Amount11],
Case when MONTH([Issuing Date])=12 then sum(dbo.[Fact Proposal].[Proposal Amount (Euro)]) else 0 end as [Amount12],
Case when MONTH([Issuing Date])=1 then sum(dbo.[Fact Proposal].[Proposal Amount (Euro)]*[CAT N]/100) else 0 end as [AmountCAT1],
Case when MONTH([Issuing Date])=2 then sum(dbo.[Fact Proposal].[Proposal Amount (Euro)]*[CAT N]/100) else 0 end as [AmountCAT2],
Case when MONTH([Issuing Date])=3 then sum(dbo.[Fact Proposal].[Proposal Amount (Euro)]*[CAT N]/100) else 0 end as [AmountCAT3],
Case when MONTH([Issuing Date])=4 then sum(dbo.[Fact Proposal].[Proposal Amount (Euro)]*[CAT N]/100) else 0 end as [AmountCAT4],
Case when MONTH([Issuing Date])=5 then sum(dbo.[Fact Proposal].[Proposal Amount (Euro)]*[CAT N]/100) else 0 end as [AmountCAT5],
Case when MONTH([Issuing Date])=6 then sum(dbo.[Fact Proposal].[Proposal Amount (Euro)]*[CAT N]/100) else 0 end as [AmountCAT6],
Case when MONTH([Issuing Date])=7 then sum(dbo.[Fact Proposal].[Proposal Amount (Euro)]*[CAT N]/100) else 0 end as [AmountCAT7],
Case when MONTH([Issuing Date])=8 then sum(dbo.[Fact Proposal].[Proposal Amount (Euro)]*[CAT N]/100) else 0 end as [AmountCAT8],
Case when MONTH([Issuing Date])=9 then sum(dbo.[Fact Proposal].[Proposal Amount (Euro)]*[CAT N]/100) else 0 end as [AmountCAT9],
Case when MONTH([Issuing Date])=10 then sum(dbo.[Fact Proposal].[Proposal Amount (Euro)]*[CAT N]/100) else 0 end as [AmountCAT10],
Case when MONTH([Issuing Date])=11 then sum(dbo.[Fact Proposal].[Proposal Amount (Euro)]*[CAT N]/100) else 0 end as [AmountCAT11],
Case when MONTH([Issuing Date])=12 then sum(dbo.[Fact Proposal].[Proposal Amount (Euro)]*[CAT N]/100) else 0 end as [AmountCAT12]
FROM dbo.[Fact Proposal] INNER JOIN
dbo.[Dim Company] ON dbo.[Fact Proposal].Company_Key = dbo.[Dim Company].Company_Key
WHERE [GKA] <>'' and [GKA]IS NOT NULL and LEFT([Proposal Status], 3) >= '020'
group by dbo.[Dim Company].GKA,
dbo.[Dim Company].[ZIG Number],
dbo.[Fact Proposal].[Country Code],
dbo.[Fact Proposal].[Reporting Line],
CASE WHEN left([Proposal Type],3)='New' then 'New Proposal'
WHEN left([Proposal Type],3)='Ren' then 'Renewal' else null end,
CASE WHEN LEFT([Proposal Status], 3) >= '020' THEN 'Issued' ELSE NULL END, [Issuing Date] |
Partager