SELECT [Market_Area], [RegionName], Morphology_Name,ALL_Sectors, Breaking_Sectors,SectorFixes,CAPTS, (x.SectorFixes * x.CAPTS) AS Spending
FROM
(
SELECT T.[Market_Area], T.[RegionName], T.Morphology_Name,T.ALL_Sectors, E.Breaking_Sectors,
Case
When T.Morphology_Name = 'Dense'
THEN IIF(T.ALL_Sectors * ((cast(E.Breaking_Sectors as float) / cast(T.ALL_Sectors as float)) - param1) > 0, ROUND(T.ALL_Sectors * ((cast(E.Breaking_Sectors as float) / cast(T.ALL_Sectors as float)) - param1),0), 0)
When T.Morphology_Name = 'Urban'
THEN IIF(T.ALL_Sectors * ((cast(E.Breaking_Sectors as float) / cast(T.ALL_Sectors as float)) - param2) > 0, ROUND(T.ALL_Sectors * ((cast(E.Breaking_Sectors as float) / cast(T.ALL_Sectors as float)) - param2),0), 0)
When T.Morphology_Name = 'Rural'
THEN IIF(T.ALL_Sectors * ((cast(E.Breaking_Sectors as float) / cast(T.ALL_Sectors as float)) - param3) > 0, ROUND(T.ALL_Sectors * ((cast(E.Breaking_Sectors as float) / cast(T.ALL_Sectors as float)) - param3),0), 0)
END AS SectorFixes,
E.CAPTS
FROM
(
(
SELECT T.[Market_Area], T.[RegionName], T.Morphology_Name,COUNT(*) AS ALL_Sectors
FROM [VPI].[dbo].[v_VPI_APT_agg1_Area_ALL] as T
WHERE [Market_Area]= 'parama' AND RegionName = 'paramr'
group by [Market_Area],[RegionName],Morphology_Name
) T
LEFT JOIN
(
SELECT [Market_Area], [RegionName],Morphology_Name,COUNT(*) AS Breaking_Sectors,CAPTS
FROM [VPI].[dbo].[v_Capital_Sector_Detail_Final_SCORE] S
WHERE [Market_Area]= 'parama' AND RegionName = 'paramr'
AND ((UPTP1 < '5' AND Morphology_Name='Dense') OR (UPTP1 < '3' AND Morphology_Name='Urban') OR (UPTP1 < '3' AND Morphology_Name='Rural'))
group by [Market_Area],[RegionName],Morphology_Name,CAPTS
) E
ON E.Market_Area = T.Market_Area and E.Morphology_Name = T.Morphology_Name
)
) x
↧