@@ -31,12 +31,56 @@ BEGIN
31
31
@WeightInsuredPopulation DECIMAL (5 , 2 ),
32
32
@WeightNumberInsuredFamilies DECIMAL (5 , 2 ),
33
33
@WeightNumberVisits DECIMAL (5 , 2 ),
34
- @WeightAdjustedAmount DECIMAL (5 , 2 )
34
+ @WeightAdjustedAmount DECIMAL (5 , 2 ),
35
+ @RP Char (1 ),
36
+ @TargetQuarter INT ,
37
+ @startDateQuarter DATE ,
38
+ @startDateYear DATE ,
39
+ @startDateMonth DATE ,
40
+ @FirstDay DATE ,
41
+ @LastDay DATE
35
42
36
43
37
- DECLARE @FirstDay DATE = CAST (@Year AS VARCHAR (4 )) + ' -' + CAST (@Month AS VARCHAR (2 )) + ' -01'
38
- DECLARE @LastDay DATE = EOMONTH (@FirstDay, 0 )
39
- DECLARE @DaysInMonth INT = DATEDIFF (DAY ,@FirstDay,DATEADD (MONTH ,1 ,@FirstDay))
44
+ -- get the product data
45
+ SELECT @Level1 = Level1,
46
+ @Sublevel1 = Sublevel1,
47
+ @Level2 = Level2,
48
+ @Sublevel2 = Sublevel2,
49
+ @Level3 = Level3,
50
+ @Sublevel3 = Sublevel3,
51
+ @Level4 = Level4,
52
+ @Sublevel4 = Sublevel4,
53
+ @ShareContribution = ISNULL (ShareContribution, 0 ),
54
+ @WeightPopulation = ISNULL (WeightPopulation, 0 ),
55
+ @WeightNumberFamilies = ISNULL (WeightNumberFamilies, 0 ),
56
+ @WeightInsuredPopulation = ISNULL (WeightInsuredPopulation, 0 ),
57
+ @WeightNumberInsuredFamilies = ISNULL (WeightNumberInsuredFamilies, 0 ),
58
+ @WeightNumberVisits = ISNULL (WeightNumberVisits, 0 ),
59
+ @WeightAdjustedAmount = ISNULL (WeightAdjustedAmount, 0 ),
60
+ @RP = ( CASE WHEN PeriodRelPrices is not NULL then PeriodRelPrices
61
+ WHEN PeriodRelPricesOP is not NULL THEN PeriodRelPricesOP
62
+ WHEN PeriodRelPricesIP is not NULL THEN PeriodRelPricesIP ELSE ' M' END )
63
+ FROM tblProduct Prod
64
+ WHERE ProdId = @ProdId
65
+
66
+ set @startDateMonth = DATEFROMPARTS (@Year, @Month ,' 01' )
67
+ set @startDateYear = DATEFROMPARTS (@Year, ' 01' ,' 01' )
68
+ IF @Month = 3 or @Month = 6 OR @Month = 9 OR @Month = 12
69
+ BEGIN
70
+ SET @TargetQuarter = @Month / 3
71
+ SET @startDateQuarter = DATEFROMPARTS (@Year, (@TargetQuarter - 1 )* 3 + 1 ,' 01' )
72
+ END
73
+ ELSE
74
+ SET @startDateQuarter = NULL
75
+
76
+
77
+ set @LastDay = EOMONTH (@startDateMonth, 0 )
78
+ SELECT @FirstDay = CASE @RP WHEN ' M' THEN @FirstDay
79
+ WHEN ' Q' THEN @startDateQuarter
80
+ WHEN ' Y' THEN @startDateYear END
81
+
82
+ if @FirstDay IS NULL
83
+ RETURN
40
84
41
85
set @DistrictId = CASE @DistrictId WHEN 0 THEN NULL ELSE @DistrictId END
42
86
@@ -84,24 +128,7 @@ BEGIN
84
128
85
129
declare @listOfHF table (id int )
86
130
87
- -- get the product data
88
- SELECT @Level1 = Level1,
89
- @Sublevel1 = Sublevel1,
90
- @Level2 = Level2,
91
- @Sublevel2 = Sublevel2,
92
- @Level3 = Level3,
93
- @Sublevel3 = Sublevel3,
94
- @Level4 = Level4,
95
- @Sublevel4 = Sublevel4,
96
- @ShareContribution = ISNULL (ShareContribution, 0 ),
97
- @WeightPopulation = ISNULL (WeightPopulation, 0 ),
98
- @WeightNumberFamilies = ISNULL (WeightNumberFamilies, 0 ),
99
- @WeightInsuredPopulation = ISNULL (WeightInsuredPopulation, 0 ),
100
- @WeightNumberInsuredFamilies = ISNULL (WeightNumberInsuredFamilies, 0 ),
101
- @WeightNumberVisits = ISNULL (WeightNumberVisits, 0 ),
102
- @WeightAdjustedAmount = ISNULL (WeightAdjustedAmount, 0 )
103
- FROM tblProduct Prod
104
- WHERE ProdId = @ProdId
131
+
105
132
106
133
-- get the list of Hf part of the covered regions and config
107
134
IF (@RegionId IS NULL or @RegionId = 0 ) AND (@DistrictId is NULL or @DistrictId = 0 )
0 commit comments