Hi,
I have the below query.I am passing the param to SP and @month is of yyyy-MM format.Basically whenever the @month is any month other than quarter end month,i calculate value from previous quarter end else i calculate the value for quarter end month.Example:
for @month=2020-07,calculate value from case_month=2020-06
for @month=2020-08,calculate value from case_month=2020-06
for @month=2020-09,calculate value from case_month=2020-09
select 'Failure Rate' as KPIname,case when @month in
(format(dateadd(d, -1, DATEADD(q, DATEDIFF(q, 0, @Case _date) + 1, 0)) ,'yyyy-MM')) then
(select round(cast(OnTime as float)/cast(Ontime+NotOnTime+PastDue as float)*100,2)
from Cust_vw a where a.case_month= (format(dateadd(d, -1, DATEADD(q, DATEDIFF(q, 0, @Case _date) + 1, 0)) ,'yyyy-MM')))
else (select round(cast(OnTime as float)/cast(Ontime+NotOnTime+PastDue as float)*100,2)
from Cust_vw a where a.case_month= (format(dateadd(d, -1, DATEADD(q, DATEDIFF(q, 0, @ADMIN _metric_date) , 0)) ,'yyyy-MM')) )
end as 'value'
I want to use the same case conditions to return the products based on the @month values.Requirement:
- case when @month in
(format(dateadd(d, -1, DATEADD(q, DATEDIFF(q, 0, @Case _date) + 1, 0)) ,'yyyy-MM')) then select all products for last month of previous quarter
Example : 2020-07 as @month,choose all products for case_month=2020-06
- case when @month not in
(format(dateadd(d, -1, DATEADD(q, DATEDIFF(q, 0, @Case _date) + 1, 0)) ,'yyyy-MM')) then select all products for @month
Example : 2020-09 as @month,choose all products for case_month=2020-09
Sample data of Cust_vw:
Expected sample with 2 columns namely KPIName as 'Failure Rate' and productmodel per row.