Good Morning. Glad I found this forum.
I have the following problem. I have a view that applies attributes to fields via case statements. That view is then used as a source of a select query inside a stored procedure to run modeling calculations and display data in database connected excel workbook. Problem is that two attributes in this view are dynamic and should be parameterized
case when fpe<='2016-03-31' then 'Ongoing'
when fpe is null then 'Ongoing'
when fpe='' then 'Ongoing'
else 'New'
end as Calc_FPE_New_Ongoing_grp,
case
when cast (MonthDisplayKey+'-01' as date)<='2016-06-30' then 'Current'
else 'Future'
End
as Calc_current_future_quarter,
What I am attempting to do is to alter the view with stored procedure and pass date parameters for fpe and monthdisplay key so user as a step one can rebuild the view and as a step 2 run calculation against the updated view. What is the way to accomplish this? Thank you for your help.
CREATE view [DW].[PVPA_PULL_VW]
as
select
a.SnapshotName,
a.cost_unit,
a.New_Study_Category,
a.MRL_Short_Franchise,
a.Calc_TA_Area_Grp,
a.activity_unique_id,
a.MK_or_V,
a.study_filing_status,
a.Calc_Filing_Status_Grp,
a.prioritization_category,
a.calc_Prioritization_grp,
a.FPE,
a.Calc_FPE_New_Ongoing_grp,
a.Execution_Project_Name,
a.Execution_Project_Sequence,
a.calc_execution_project_sequence_grp,
a.Current_Clinical_Phase,
a.Study_Phase,
a.MonthDisplayKey as Forecast_Month,
a.Calc_current_future_quarter,
a.GrossAmount,
a.Calc_TA_Area_Grp+a.Calc_Filing_Status_Grp+a.calc_Prioritization_grp+a.Calc_FPE_New_Ongoing_grp+a.Calc_current_future_quarter+a.calc_execution_project_sequence_grp as FK_Rules_Unique_Id,
a.SnapshotName+a.activity_unique_id as FK_PTRS_Unique_ID
from
(select snapshotName,
cost_unit,
New_Study_Category,
MRL_Short_Franchise,--========Therapeutic Area Group --MK-3475 is PD1 -- Licensed Compound Check is Cubist --The rest follow MRL Short Franchise
case when MK_or_V='MK-3475' then 'PD1' when Licensed_Compound_Check='Cubist' then MRL_Short_Franchise+' (Cubist)' when MRL_Short_Franchise not in ('CV','D&E','ID','N&O','Onc','R&I','Vac') then 'Other' else MRL_Short_Franchise end as Calc_TA_Area_Grp, activity_unique_id, MK_or_V, study_filing_status,
--======Study Filing Status Group.======= --Authorized, NA,Cancelled,Cancelled- work ongoing=Authorized --Projected, On Hold=Projected --Rest NA case when study_filing_status='Authorized' then 'Authorized' when study_filing_status='NA' then 'Authorized' when study_filing_status='Cancelled' then 'Authorized' when study_filing_status='Cancelled - work ongoing' then 'Authorized' --when study_filing_status='On Hold' then 'Authorized' when study_filing_status='Projected' then 'Projected' when study_filing_status='On Hold' then 'Projected' else 'NA' end as Calc_Filing_Status_Grp,
prioritization_category, case when MK_or_V<>'MK-3475' and Prioritization_Category='Continue' then 'Medium/Continue' when MK_or_V<>'MK-3475' and Prioritization_Category='High' then 'Medium/Continue' when MK_or_V<>'MK-3475' and Prioritization_Category='Medium' then 'Medium/Continue' when MK_or_V<>'MK-3475' and Prioritization_Category='Unrated' then 'Medium/Continue' when MK_or_V<>'MK-3475' and Prioritization_Category='BLOCK' then 'Medium/Continue' when MK_or_V<>'MK-3475' and Prioritization_Category='Low' then 'Low/Gated' when MK_or_V<>'MK-3475' and Prioritization_Category='Gated' then 'Low/Gated' when MK_or_V='MK-3475' and Prioritization_Category='High' then 'High' when MK_or_V='MK-3475' and Prioritization_Category='Continue' then 'Medium/Continue' when MK_or_V='MK-3475' and Prioritization_Category='Medium' then 'Medium/Continue' when MK_or_V='MK-3475' and Prioritization_Category='Unrated' then 'Medium/Continue' when MK_or_V='MK-3475' and Prioritization_Category='BLOCK' then 'Medium/Continue' when MK_or_V='MK-3475' and Prioritization_Category='Low' then 'Low/Gated' when MK_or_V='MK-3475' and Prioritization_Category='Gated' then 'Low/Gated'
else 'NA' end as calc_Prioritization_grp, FPE, case ----/////////////////////// ---MANUAL UPDATE UPDATE FPE TO ONE QUARTER BEHIND FORECAST when fpe<='2016-03-31' then 'Ongoing' when fpe is null then 'Ongoing' when fpe='' then 'Ongoing' else 'New' end as Calc_FPE_New_Ongoing_grp, ----/////////////////////// ---MANUAL UPDATE UPDATE FPE TO ONE QUARTER BEHIND FORECAST Execution_Project_Name, Execution_Project_Sequence, case when Execution_Project_Sequence='Next' then 'Next/Future' when Execution_Project_Sequence='Future' then 'Next/Future' else 'Current' end as calc_execution_project_sequence_grp, Current_Clinical_Phase, Study_Phase, cast(MonthDisplayKey+'-01' as date) as MonthDisplayKey, --Current/Future Quarter ------/////////////////////// ---MANUAL UPDATE UPDATE MONTHDISPLAYKEY TO SET CURRENT FORECAST QUARTER case when cast (MonthDisplayKey+'-01' as date)<='2016-06-30' then 'Current' else 'Future' End as Calc_current_future_quarter, --Current/Future Quarter ------/////////////////////// ---MANUAL UPDATE UPDATE MONTHDISPLAYKEY TO SET CURRENT FORECAST QUARTER isnull(GrossAmount,0) as GrossAmount
from pvpa.dbo.Cost_AsReported_VW where (cost_unit='Grants' and new_study_category='Clin res' AND Activity_Unique_ID NOT LIKE '%Finance%') OR (cost_unit in('Merck Sourced Materials','Competitive Product')) and Activity_Unique_ID not like '%Finance%')as a