The following lines contain the word 'select', 'insert', 'update' or 'delete':
*SELECT WEEK_ID
*FROM fii_time_week
*WHERE to_date('14-JUL-2002','DD-MON-YYYY') >= start_date
*AND to_date('14-JUL-2002','DD-MON-YYYY') <= end_date
*
*SELECT MONTH_ID -- Get Month_id
*FROM fii_time_month -- NEED TO GET THE RIGHT TABLE FROM period_type
*WHERE to_date('14-JUL-2002','DD-MON-YYYY') >= start_date
*AND to_date('14-JUL-2002','DD-MON-YYYY') <= end_date
*
*SELECT QUARTER_ID -- GET quarter_id
*FROM fii_time_qtr
*WHERE to_date('14-JUL-2002','DD-MON-YYYY') >= start_date
*AND to_date('14-JUL-2002','DD-MON-YYYY') <= end_date
*
*SELECT YEAR_ID -- GET year_id
*FROM fii_time_year
*WHERE to_date('14-JUL-2002','DD-MON-YYYY') >= start_date
*AND to_date('14-JUL-2002','DD-MON-YYYY') <= end_date
**********************************************************/
-- get values for p_prev_page_time_id
-- ER #2467584 for gettig previous time_id e.g. TIME+FII_TIME_ENT_PERIOD_PFROM and TIME+FII_TIME_ENT_PERIOD_PTO
/* IF (p_comp_type = 'YEARLY') THEN
CASE p_page_period_type
WHEN 'FII_TIME_WEEK' THEN
l_prior_as_of_date := FII_TIME_API.sd_lyswk(l_as_of_date);
select WEEK_ID
into p_prev_page_time_id
from fii_time_week
where l_prior_as_of_date BETWEEN start_date AND end_date;
select MONTH_ID
into p_prev_page_time_id
from fii_time_month
where l_prior_as_of_date BETWEEN start_date AND end_date;
select QUARTER_ID
into p_prev_page_time_id
from fii_time_qtr
where l_prior_as_of_date BETWEEN start_date AND end_date;
select YEAR_ID
into p_prev_page_time_id
from fii_time_year
where l_prior_as_of_date BETWEEN start_date AND end_date;
select end_date
from fii_time_ent_year
where sequence =
(select sequence - num_periods
from fii_time_ent_year
where p_as_of_date between start_date and end_date);
SELECT p2.end_date
FROM fii_time_ent_period p1, fii_time_ent_period p2
WHERE p1.sequence = p2.sequence
AND p_as_of_date BETWEEN p1.start_date AND p1.end_date
AND p2.ent_year_id = p1.ent_year_id -2;
select qtr2.end_date
from fii_time_ent_qtr qtr1, fii_time_ent_qtr qtr2
where p_as_of_date between qtr1.start_date and qtr1.end_date
and qtr2.sequence = qtr1.sequence and qtr2.ent_year_id=qtr1.ent_year_id-2;
SELECT LEAF_NODE_FLAG INTO L_LEAF_NODE FROM ENI_ITEM_VBH_NODES_V
WHERE PARENT_ID = replace(l_Category_ID,'''','')
AND PARENT_ID = CHILD_ID;
SELECT /*+ leading(c) */
0 c_lds,
0 p_lds,
0 c_leads,
0 p_leads,
0 c_leads_a,
0 p_leads_a,
0 c_opps,
0 p_opps,
0 c_boa,
0 p_boa,
0 c_no_leads,
0 p_no_leads,
0 c_cost,
0 p_cost,
0 c_revenue,
0 p_revenue,
0 c_leads_open,
0 p_leads_open,
0 c_prior_open,
0 p_prior_open,
0 c_invoice_amt,
0 p_invoice_amt,
1 value,
SUM(case when c.report_date=&BIS_CURRENT_ASOF_DATE then b.cnv_opty_amt else 0 end) c_opp_amt_conv_leads,
SUM(case when c.report_date=&BIS_PREVIOUS_ASOF_DATE then b.cnv_opty_amt else 0 end) p_opp_amt_conv_leads
FROM FII_TIME_RPT_STRUCT c, ';
SELECT /*+ leading(c) */
0 c_lds,
0 p_lds,
0 c_leads,
0 p_leads,
0 c_leads_a,
0 p_leads_a,
0 c_opps,
0 p_opps,
0 c_boa,
0 p_boa,
0 c_no_leads,
0 p_no_leads,
0 c_cost,
0 p_cost,
0 c_revenue,
0 p_revenue,
0 c_leads_open,
0 p_leads_open,
0 c_prior_open,
0 p_prior_open,
0 c_invoice_amt,
0 p_invoice_amt,
1 value,
SUM(case when c.report_date=&BIS_CURRENT_ASOF_DATE then b.cnv_opty_amt_s else 0 end) c_opp_amt_conv_leads,
SUM(case when c.report_date=&BIS_PREVIOUS_ASOF_DATE then b.cnv_opty_amt_s else 0 end) p_opp_amt_conv_leads
FROM FII_TIME_RPT_STRUCT c, ';
l_qry5 := ' AND b.update_period_type_id = -1 AND b.update_time_id = -1 ';
l_qry11 := ' AND b.update_period_type_id = -1 AND b.update_time_id = -1 ';
( select edh.child_id from eni_denorm_hierarchies edh, mtl_default_category_sets d
where edh.object_type = ''CATEGORY_SET''
AND edh.object_id = d.category_set_id AND d.functional_area_id = 11 AND edh.dbi_flag = ''Y'' AND edh.parent_id = &ITEM+ENI_ITEM_VBH_CAT ) edh ';
l_qry5 := ' AND b.update_period_type_id = -1 AND b.update_time_id = -1 ';
( select edh.child_id from eni_denorm_hierarchies edh, mtl_default_category_sets d
where edh.object_type = ''CATEGORY_SET''
AND edh.object_id = d.category_set_id AND d.functional_area_id = 11 AND edh.dbi_flag = ''Y'' AND edh.parent_id = &ITEM+ENI_ITEM_VBH_CAT ) edh ';
l_qry11 := ' AND b.update_period_type_id = -1 AND b.update_time_id = -1 ';
( select edh.child_id from eni_denorm_hierarchies edh, mtl_default_category_sets d
where edh.object_type = ''CATEGORY_SET''
AND edh.object_id = d.category_set_id AND d.functional_area_id = 11 AND edh.dbi_flag = ''Y'' AND edh.parent_id = &ITEM+ENI_ITEM_VBH_CAT ) edh ';
'SELECT
c_leads BIM_MEASURE1,p_leads BIM_MEASURE2,
c_leads BIM_GRAND_TOTAL1,p_leads BIM_CGRAND_TOTAL1,
DECODE(c_leads,0,NULL,100*(c_leads_a/c_leads)) BIM_MEASURE3,
DECODE(p_leads,0,NULL,100*(p_leads_a/p_leads)) BIM_MEASURE4,
DECODE(c_leads,0,NULL,100*(c_leads_a/c_leads)) BIM_GRAND_TOTAL2,
DECODE(p_leads,0,NULL,100*(p_leads_a/p_leads)) BIM_CGRAND_TOTAL2,
0 BIM_MEASURE5, 0 BIM_MEASURE6,
0 BIM_GRAND_TOTAL3, 0 BIM_CGRAND_TOTAL3,
DECODE(c_no_leads,0,NULL,(c_boa/c_no_leads)) BIM_MEASURE7,
DECODE(p_no_leads,0,NULL,(p_boa/p_no_leads)) BIM_MEASURE8,
DECODE(c_no_leads,0,NULL,(c_boa/c_no_leads)) BIM_GRAND_TOTAL4,
DECODE(p_no_leads,0,NULL,(p_boa/p_no_leads)) BIM_CGRAND_TOTAL4,
DECODE((c_leads+c_prior_open),0,NULL,(c_opps*100/(c_prior_open+c_leads))) BIM_MEASURE9,
DECODE((p_leads+p_prior_open),0,NULL,(p_opps*100/(p_prior_open+p_leads))) BIM_MEASURE10,
DECODE((c_leads+c_prior_open),0,NULL,(c_opps*100/(c_prior_open+c_leads))) BIM_GRAND_TOTAL5,
DECODE((p_leads+p_prior_open),0,NULL,(p_opps*100/(p_prior_open+p_leads))) BIM_CGRAND_TOTAL5,
c_opps BIM_MEASURE11,p_opps BIM_MEASURE12,
c_opps BIM_GRAND_TOTAL6,p_opps BIM_CGRAND_TOTAL6,
c_boa BIM_MEASURE13,p_boa BIM_MEASURE14,
c_boa BIM_GRAND_TOTAL7,p_boa BIM_CGRAND_TOTAL7,
c_leads_open BIM_MEASURE15,p_leads_open BIM_MEASURE16,
c_leads_open BIM_GRAND_TOTAL8,p_leads_open BIM_CGRAND_TOTAL8,
c_invoice_amt BIM_MEASURE17,p_invoice_amt BIM_MEASURE18,
c_invoice_amt BIM_GRAND_TOTAL9,p_invoice_amt BIM_CGRAND_TOTAL9,
c_opp_amt_conv_leads BIM_MEASURE19,
p_opp_amt_conv_leads BIM_MEASURE20,
c_opp_amt_conv_leads BIM_GRAND_TOTAL10,
p_opp_amt_conv_leads BIM_CGRAND_TOTAL10,
c_leads_a BIM_MEASURE21,p_leads_a BIM_MEASURE22,
c_leads_a BIM_GRAND_TOTAL11,p_leads_a BIM_CGRAND_TOTAL11
FROM (
SELECT
sum(c_lds) c_lds, sum(p_lds) p_lds, sum(c_leads) c_leads, sum(p_leads) p_leads,
sum(c_leads_a) c_leads_a, sum(p_leads_a) p_leads_a, sum(c_opps) c_opps, sum(p_opps) p_opps,
sum(c_boa) c_boa, sum(p_boa) p_boa, sum(c_no_leads) c_no_leads, sum(p_no_leads) p_no_leads,
0 c_cost, 0 p_cost, sum(c_revenue) c_revenue, sum(p_revenue) p_revenue,
sum(c_leads_open) c_leads_open, sum(p_leads_open) p_leads_open,
sum(c_prior_open) c_prior_open, sum(p_prior_open) p_prior_open,
sum(c_invoice_amt) c_invoice_amt, sum(p_invoice_amt) p_invoice_amt, sum(value) value,
sum(c_opp_amt_conv_leads) c_opp_amt_conv_leads, sum(p_opp_amt_conv_leads) p_opp_amt_conv_leads
FROM ( /* Query for Current and Previous */
SELECT '||l_hint||'
SUM(case when c.report_date=&BIS_CURRENT_ASOF_DATE then b.leads else 0 end) c_lds,
SUM(case when c.report_date=&BIS_PREVIOUS_ASOF_DATE then b.leads else 0 end) p_lds,
SUM(case when c.report_date=&BIS_CURRENT_ASOF_DATE then b.leads else 0 end) c_leads,
SUM(case when c.report_date=&BIS_PREVIOUS_ASOF_DATE then b.leads else 0 end) p_leads,
SUM(case when c.report_date=&BIS_CURRENT_ASOF_DATE then b.rank_a else 0 end) c_leads_a,
SUM(case when c.report_date=&BIS_PREVIOUS_ASOF_DATE then b.rank_a else 0 end) p_leads_a,
SUM(case when c.report_date=&BIS_CURRENT_ASOF_DATE then b.leads_converted else 0 end) c_opps,
SUM(case when c.report_date=&BIS_PREVIOUS_ASOF_DATE then b.leads_converted else 0 end) p_opps,
SUM(case when c.report_date=&BIS_CURRENT_ASOF_DATE then b.orders_booked_amt else 0 end) c_boa,
SUM(case when c.report_date=&BIS_PREVIOUS_ASOF_DATE then b.orders_booked_amt else 0 end) p_boa,
SUM(case when c.report_date=&BIS_CURRENT_ASOF_DATE then b.leads_new else 0 end) c_no_leads,
SUM(case when c.report_date=&BIS_PREVIOUS_ASOF_DATE then b.leads_new else 0 end) p_no_leads,
0 c_cost,
0 p_cost,
SUM(case when c.report_date=&BIS_CURRENT_ASOF_DATE then b.orders_booked_amt*b.leads_new/DECODE(b.leads,0,1,b.leads) else 0 end) c_revenue,
SUM(case when c.report_date=&BIS_PREVIOUS_ASOF_DATE then b.orders_booked_amt*b.leads_new/DECODE(b.leads,0,1,b.leads) else 0 end) p_revenue,
0 c_leads_open,
0 p_leads_open,
0 c_prior_open,
0 p_prior_open,
SUM(case when c.report_date=&BIS_CURRENT_ASOF_DATE then b.orders_invoiced_amt else 0 end) c_invoice_amt,
SUM(case when c.report_date=&BIS_PREVIOUS_ASOF_DATE then b.orders_invoiced_amt else 0 end) p_invoice_amt,
1 value,
0 c_opp_amt_conv_leads, 0 p_opp_amt_conv_leads
FROM (
SELECT report_date,time_id,period_type_id
FROM FII_TIME_RPT_STRUCT
WHERE calendar_id=-1
AND report_date IN (&BIS_CURRENT_ASOF_DATE,&BIS_PREVIOUS_ASOF_DATE)
AND BITAND(record_type_id,:l_record_type)=record_type_id) c, ';
SELECT '||l_hint||'
0 c_lds,
0 p_lds,
0 c_leads,
0 p_leads,
0 c_leads_a,
0 p_leads_a,
0 c_opps,
0 p_opps,
0 c_boa,
0 p_boa,
0 c_no_leads,
0 p_no_leads,
0 c_cost,
0 p_cost,
0 c_revenue,
0 p_revenue,
SUM(case when c.report_date=&BIS_CURRENT_ASOF_DATE then b.leads-(b.leads_closed+b.leads_dead+b.leads_converted) else 0 end) c_leads_open,
SUM(case when c.report_date=&BIS_PREVIOUS_ASOF_DATE then b.leads-(b.leads_closed+b.leads_dead+b.leads_converted) else 0 end) p_leads_open,
SUM(case when c.report_date=&BIS_CURRENT_EFFECTIVE_START_DATE - 1 then b.leads-(b.leads_closed+b.leads_dead+b.leads_converted) else 0 end) c_prior_open,
SUM(case when c.report_date=&BIS_PREVIOUS_EFFECTIVE_START_DATE - 1 then b.leads-(b.leads_closed+b.leads_dead+b.leads_converted) else 0 end) p_prior_open,
0 c_invoice_amt,
0 p_invoice_amt,
1 value,
0 c_opp_amt_conv_leads,
0 p_opp_amt_conv_leads
FROM FII_TIME_RPT_STRUCT c, ';
l_query :='SELECT c_lead_age BIM_MEASURE1, p_lead_age BIM_MEASURE2,
c_lead_age BIM_GRAND_TOTAL1, p_lead_age BIM_CGRAND_TOTAL1,
c_a_lead_age BIM_MEASURE3, p_a_lead_age BIM_MEASURE4,
c_a_lead_age BIM_GRAND_TOTAL2, p_a_lead_age BIM_CGRAND_TOTAL2
FROM(SELECT
decode(sum(c_leads_open),0,NULL,sum(c_days)/sum(c_leads_open))c_lead_age,
decode(sum(p_leads_open),0,NULL,sum(p_days)/sum(p_leads_open))p_lead_age,
decode(sum(c_aleads_open),0,null,sum(c_adays)/sum(c_aleads_open))c_a_lead_age,
decode(sum(p_aleads_open),0,null,sum(p_adays)/sum(p_aleads_open))p_a_lead_age
FROM bim_i_ld_age_sg_mv a
WHERE a.group_id = &ORGANIZATION+JTF_ORG_SALES_GROUP
AND a.resource_id = -1
) a';
l_query :='SELECT c_lead_age BIM_MEASURE1, p_lead_age BIM_MEASURE2,
c_lead_age BIM_GRAND_TOTAL1, p_lead_age BIM_CGRAND_TOTAL1,
c_a_lead_age BIM_MEASURE3, p_a_lead_age BIM_MEASURE4,
c_a_lead_age BIM_GRAND_TOTAL2, p_a_lead_age BIM_CGRAND_TOTAL2
FROM(SELECT
decode(sum(c_leads_open),0,NULL,sum(c_days)/sum(c_leads_open))c_lead_age,
decode(sum(p_leads_open),0,NULL,sum(p_days)/sum(p_leads_open))p_lead_age,
decode(sum(c_aleads_open),0,null,sum(c_adays)/sum(c_aleads_open))c_a_lead_age,
decode(sum(p_aleads_open),0,null,sum(p_adays)/sum(p_aleads_open))p_a_lead_age
FROM bim_i_ld_age_sg_mv a
WHERE a.group_id = :l_group_id
AND a.resource_id = :l_resource_id ) a';
l_query :='SELECT c_lead_age BIM_MEASURE1, p_lead_age BIM_MEASURE2,
c_lead_age BIM_GRAND_TOTAL1, p_lead_age BIM_CGRAND_TOTAL1,
c_a_lead_age BIM_MEASURE3, p_a_lead_age BIM_MEASURE4,
c_a_lead_age BIM_GRAND_TOTAL2, p_a_lead_age BIM_CGRAND_TOTAL2
FROM(SELECT
decode(sum(c_leads_open),0,NULL,sum(c_days)/sum(c_leads_open))c_lead_age,
decode(sum(p_leads_open),0,NULL,sum(p_days)/sum(p_leads_open))p_lead_age,
decode(sum(c_aleads_open),0,null,sum(c_adays)/sum(c_aleads_open))c_a_lead_age,
decode(sum(p_aleads_open),0,null,sum(p_adays)/sum(p_aleads_open))p_a_lead_age
FROM bim_i_lp_age_sg_mv a
WHERE a.group_id = &ORGANIZATION+JTF_ORG_SALES_GROUP
AND a.product_category_id = &ITEM+ENI_ITEM_VBH_CAT
AND a.resource_id = -1
AND a.umark = 3
) a';
FROM(SELECT
decode(sum(c_leads_open),0,NULL,sum(c_days)/sum(c_leads_open))c_lead_age,
decode(sum(p_leads_open),0,NULL,sum(p_days)/sum(p_leads_open))p_lead_age,
decode(sum(c_aleads_open),0,null,sum(c_adays)/sum(c_aleads_open))c_a_lead_age,
decode(sum(p_aleads_open),0,null,sum(p_adays)/sum(p_aleads_open))p_a_lead_age
FROM bim_i_lp_age_sg_mv a
WHERE a.group_id = :l_group_id
AND a.product_category_id = &ITEM+ENI_ITEM_VBH_CAT
AND a.resource_id = :l_resource_id AND a.umark = 3 ) a';
l_query := 'SELECT
NULL VIEWBY,
NULL VIEWBYID,
NULL BIM_MEASURE1,
NULL BIM_MEASURE2,
NULL BIM_MEASURE3,
NULL BIM_MEASURE4,
NULL BIM_MEASURE5,
NULL BIM_MEASURE6,
NULL BIM_MEASURE8,
NULL BIM_MEASURE7,
NULL BIM_MEASURE9,
NULL BIM_URL1,
NULL BIM_URL2,
NULL BIM_URL3,
NULL BIM_URL4,
NULL BIM_URL5,
NULL BIM_URL6,
NULL BIM_URL7,
NULL BIM_GRAND_TOTAL1,
NULL BIM_GRAND_TOTAL2,
NULL BIM_GRAND_TOTAL3,
NULL BIM_GRAND_TOTAL4,
NULL BIM_GRAND_TOTAL5,
NULL BIM_GRAND_TOTAL6,
NULL bim_GRAND_TOTAL7,
NULL bim_GRAND_TOTAL8,
NULL bim_GRAND_TOTAL9
FROM dual';
AND b.update_time_id=-1
AND b.update_period_type_id =-1
AND b.resource_id = :l_resource_id ';
AND b.update_time_id=-1
AND b.update_period_type_id =-1
AND b.resource_id <> :l_resource_id ';
AND b.update_time_id=-1
AND b.update_period_type_id=-1
AND b.resource_id = :l_resource_id ';
AND b.update_time_id=-1
AND b.update_period_type_id=-1
AND b.resource_id <> :l_resource_id ';
AND b.update_time_id=-1
AND b.update_period_type_id=-1
AND b.resource_id =:l_resource_id ';
AND b.update_time_id=-1
AND b.update_period_type_id=-1
AND b.resource_id =:l_resource_id ';
AND b.update_time_id=-1
AND b.update_period_type_id =-1
AND b.resource_id = :l_resource_id
AND b.product_category_id = edh.child_id AND edh.object_type = ''CATEGORY_SET'' AND edh.object_id = mtl.category_set_id AND mtl.functional_area_id = 11 AND edh.dbi_flag = ''Y'' AND edh.parent_id = &ITEM+ENI_ITEM_VBH_CAT ';
AND b.update_time_id=-1
AND b.update_period_type_id =-1
AND b.resource_id <> :l_resource_id
AND b.product_category_id = edh.child_id AND edh.object_type = ''CATEGORY_SET'' AND edh.object_id = mtl.category_set_id AND mtl.functional_area_id = 11 AND edh.dbi_flag = ''Y'' AND edh.parent_id = &ITEM+ENI_ITEM_VBH_CAT ';
AND b.update_time_id=-1
AND b.update_period_type_id=-1
AND b.resource_id = :l_resource_id
AND b.product_category_id = edh.child_id AND edh.object_type = ''CATEGORY_SET'' AND edh.object_id = mtl.category_set_id AND mtl.functional_area_id = 11 AND edh.dbi_flag = ''Y'' AND edh.parent_id = &ITEM+ENI_ITEM_VBH_CAT ';
AND b.update_time_id=-1
AND b.update_period_type_id=-1
AND b.resource_id <> :l_resource_id
AND b.product_category_id = edh.child_id AND edh.object_type = ''CATEGORY_SET'' AND edh.object_id = mtl.category_set_id AND mtl.functional_area_id = 11 AND edh.dbi_flag = ''Y'' AND edh.parent_id = &ITEM+ENI_ITEM_VBH_CAT ';
AND b.update_time_id=-1
AND b.update_period_type_id=-1
AND b.resource_id = :l_resource_id
AND b.product_category_id = edh.child_id AND edh.object_type = ''CATEGORY_SET'' AND edh.object_id = mtl.category_set_id AND mtl.functional_area_id = 11 AND edh.dbi_flag = ''Y'' AND edh.parent_id = &ITEM+ENI_ITEM_VBH_CAT ';
AND b.update_time_id=-1
AND b.update_period_type_id=-1
AND b.resource_id = :l_resource_id
AND b.product_category_id = edh.child_id AND edh.object_type = ''CATEGORY_SET'' AND edh.object_id = mtl.category_set_id AND mtl.functional_area_id = 11 AND edh.dbi_flag = ''Y'' AND edh.parent_id = &ITEM+ENI_ITEM_VBH_CAT ';
' SELECT BIM_SALES_GROUP VIEWBY,
VIEWBYID,
prior_open BIM_MEASURE1,
leads_new BIM_MEASURE2,
leads_converted BIM_MEASURE3,
leads_dead BIM_MEASURE4,
curr_open BIM_MEASURE5,
(curr_total-curr_leads_changed) BIM_MEASURE6,
leads_closed BIM_MEASURE8,
DECODE(curr_open,0,0,((curr_total-curr_leads_changed)/curr_open)*100) BIM_MEASURE7,
leads_converted BIM_MEASURE9,
NULL BIM_URL1,
DECODE(leaf_node_flag,''Y'',NULL,'||''''||l_url_str||''''||' ) BIM_URL2,
decode(VIEWBYID,-1,null,decode(leads_new,0,NULL,'||''''||l_url_str1||''''||'||'||''''||l_Metric_a||''''||'||'||''''||l_rpt_name||''''||'||VIEWBYID'||'||'||''''||l_context_info||')) BIM_URL3,
decode(VIEWBYID,-1,null,decode(leads_converted,0,NULL,'||''''||l_url_str2||''''||'||'||''''||l_Metric_b||''''||'||'||''''||l_rpt_name||''''||'||VIEWBYID'||'||'||''''||l_context_info||')) BIM_URL4,
decode(VIEWBYID,-1,null,decode(leads_closed,0,NULL,'||''''||l_url_str3||''''||'||'||''''||l_Metric_c||''''||'||'||''''||l_rpt_name||''''||'||VIEWBYID'||'||'||''''||l_context_info||')) BIM_URL5,
decode(VIEWBYID,-1,null,decode(curr_open,0,NULL,'||''''||l_url_str4||''''||'||'||''''||l_Metric_d||''''||'||'||''''||l_rpt_name||''''||'||VIEWBYID'||'||'||''''||l_context_info||')) BIM_URL6,
decode(VIEWBYID,-1,null,decode((curr_total-curr_leads_changed),0,NULL,'||''''||l_url_str5||''''||'||'||''''||l_Metric_e||''''||'||'||''''||l_rpt_name||''''||'||VIEWBYID'||'||'||''''||l_context_info||')) BIM_URL7,
SUM(prior_open) OVER() BIM_GRAND_TOTAL1,
SUM(leads_new) OVER() BIM_GRAND_TOTAL2,
SUM(leads_converted) OVER() BIM_GRAND_TOTAL3,
SUM(leads_dead) OVER() BIM_GRAND_TOTAL4,
SUM(curr_open) OVER() BIM_GRAND_TOTAL5,
SUM(curr_total-curr_leads_changed) OVER() BIM_GRAND_TOTAL6,
DECODE(SUM(curr_open) OVER(),0,0,(SUM(curr_total-curr_leads_changed) OVER()/SUM(curr_open) OVER())*100) BIM_GRAND_TOTAL7,
SUM(leads_closed) OVER() BIM_GRAND_TOTAL8,
SUM(leads_converted) OVER() BIM_GRAND_TOTAL9
FROM
(
select BIM_SALES_GROUP,
VIEWBYID,
leaf_node_flag,
sum(prior_open) prior_open,
sum(curr_open) curr_open,
sum(curr_total) curr_total,
sum(leads_converted) leads_converted,
sum(leads_new) leads_new,
sum(leads_dead) leads_dead,
sum(leads_closed) leads_closed,
sum(curr_leads_changed) curr_leads_changed
FROM
(
select /*+ ORDERED */
p.value BIM_SALES_GROUP,
p.parent_id VIEWBYID,
p.leaf_node_flag leaf_node_flag,
SUM(case when c.report_date=&BIS_CURRENT_EFFECTIVE_START_DATE - 1 and &BIS_CURRENT_EFFECTIVE_START_DATE <> :g_start_date then b.leads-(b.leads_closed+b.leads_dead+b.leads_converted) else 0 end) prior_open,
SUM(case when c.report_date=&BIS_CURRENT_ASOF_DATE then b.leads-(b.leads_closed+b.leads_dead+b.leads_converted) else 0 end) curr_open,
SUM(case when c.report_date=&BIS_CURRENT_ASOF_DATE then b.leads else 0 end) curr_total,
0 leads_converted,
0 leads_new,
0 leads_dead,
0 leads_closed,
SUM(case when c.report_date=&BIS_CURRENT_ASOF_DATE then b.leads_changed else 0 end) curr_leads_changed
FROM FII_TIME_RPT_STRUCT c, BIM_I_LP_GEN_SG_MV b,
( SELECT e.parent_id parent_id ,e.value value,e.leaf_node_flag leaf_node_flag
FROM eni_item_vbh_nodes_v e
WHERE e.top_node_flag=''Y''
AND e.child_id = e.parent_id) p
,eni_denorm_hierarchies edh
,mtl_default_category_sets d
WHERE
b.group_id = &ORGANIZATION+JTF_ORG_SALES_GROUP
AND b.product_category_id = edh.child_id
AND edh.object_type = ''CATEGORY_SET''
AND edh.object_id = d.category_set_id
AND d.functional_area_id = 11
AND edh.dbi_flag = ''Y''
AND edh.parent_id = p.parent_id
AND c.calendar_id=-1
AND c.report_date in (&BIS_CURRENT_ASOF_DATE,&BIS_CURRENT_EFFECTIVE_START_DATE - 1)
AND BITAND(c.record_type_id,1143)=c.record_type_id
AND b.time_id=c.time_id
AND b.period_type_id=c.period_type_id
AND b.update_period_type_id = -1
AND b.update_time_id = -1
AND b.resource_id = :l_resource_id
GROUP BY p.value,p.parent_id,p.leaf_node_flag
UNION ALL
/*Others for sales group*/
select /*+ ORDERED */
p.value BIM_SALES_GROUP,
p.parent_id VIEWBYID,
p.leaf_node_flag leaf_node_flag,
0 prior_open,
0 curr_open,
0 curr_total,
sum(leads_converted) leads_converted,
sum(leads_new) leads_new,
sum(leads_dead) leads_dead,
sum(leads_closed) leads_closed,
0 curr_leads_changed
FROM FII_TIME_RPT_STRUCT c, BIM_I_LP_GEN_SG_MV b,
( SELECT e.parent_id parent_id ,e.value value,e.leaf_node_flag leaf_node_flag
FROM eni_item_vbh_nodes_v e
WHERE e.top_node_flag=''Y''
AND e.child_id = e.parent_id) p
,eni_denorm_hierarchies edh
,mtl_default_category_sets d
WHERE
b.group_id = &ORGANIZATION+JTF_ORG_SALES_GROUP
AND b.product_category_id = edh.child_id
AND edh.object_type = ''CATEGORY_SET''
AND edh.object_id = d.category_set_id
AND d.functional_area_id = 11
AND edh.dbi_flag = ''Y''
AND edh.parent_id = p.parent_id
AND c.calendar_id=-1
AND c.report_date = &BIS_CURRENT_ASOF_DATE
AND BITAND(c.record_type_id,:l_record_type)=c.record_type_id
AND b.time_id=c.time_id
AND b.period_type_id=c.period_type_id
AND b.update_period_type_id = -1
AND b.update_time_id = -1
AND b.resource_id = :l_resource_id
AND ( leads_converted <> 0 or leads_new <> 0 or leads_dead <> 0 or leads_closed <> 0 )
GROUP BY p.value,p.parent_id,p.leaf_node_flag
)
GROUP BY BIM_SALES_GROUP,VIEWBYID,leaf_node_flag
HAVING
sum(prior_open) > 0
OR sum(leads_new) > 0
OR sum(leads_converted) > 0
OR sum(leads_dead) > 0
OR sum(curr_open) > 0
OR sum(curr_total)-sum(curr_leads_changed) > 0
OR sum(leads_closed) > 0
) &ORDER_BY_CLAUSE';
'SELECT BIM_SALES_GROUP VIEWBY,
VIEWBYID,
prior_open BIM_MEASURE1,
leads_new BIM_MEASURE2,
leads_converted BIM_MEASURE3,
leads_dead BIM_MEASURE4,
curr_open BIM_MEASURE5,
(curr_total-curr_leads_changed) BIM_MEASURE6,
leads_closed BIM_MEASURE8,
DECODE(curr_open,0,0,((curr_total-curr_leads_changed)/curr_open)*100) BIM_MEASURE7,
leads_converted BIM_MEASURE9,
NULL BIM_URL1,
DECODE(leaf_node_flag,''Y'',NULL,'||''''||l_url_str||''''||' ) BIM_URL2,
decode(VIEWBYID,-1,null,decode(leads_new,0,NULL,'||''''||l_url_str1||''''||'||'||''''||l_Metric_a||''''||'||'||''''||l_rpt_name||''''||'||VIEWBYID'||'||'||''''||l_context_info||')) BIM_URL3,
decode(VIEWBYID,-1,null,decode(leads_converted,0,NULL,'||''''||l_url_str2||''''||'||'||''''||l_Metric_b||''''||'||'||''''||l_rpt_name||''''||'||VIEWBYID'||'||'||''''||l_context_info||')) BIM_URL4,
decode(VIEWBYID,-1,null,decode(leads_closed,0,NULL,'||''''||l_url_str3||''''||'||'||''''||l_Metric_c||''''||'||'||''''||l_rpt_name||''''||'||VIEWBYID'||'||'||''''||l_context_info||')) BIM_URL5,
decode(VIEWBYID,-1,null,decode(curr_open,0,NULL,'||''''||l_url_str4||''''||'||'||''''||l_Metric_d||''''||'||'||''''||l_rpt_name||''''||'||VIEWBYID'||'||'||''''||l_context_info||')) BIM_URL6,
decode(VIEWBYID,-1,null,decode((curr_total-curr_leads_changed),0,NULL,'||''''||l_url_str5||''''||'||'||''''||l_Metric_e||''''||'||'||''''||l_rpt_name||''''||'||VIEWBYID'||'||'||''''||l_context_info||')) BIM_URL7,
SUM(prior_open) OVER() BIM_GRAND_TOTAL1,
SUM(leads_new) OVER() BIM_GRAND_TOTAL2,
SUM(leads_converted) OVER() BIM_GRAND_TOTAL3,
SUM(leads_dead) OVER() BIM_GRAND_TOTAL4,
SUM(curr_open) OVER() BIM_GRAND_TOTAL5,
SUM(curr_total-curr_leads_changed) OVER() BIM_GRAND_TOTAL6,
DECODE(SUM(curr_open) OVER(),0,0,(SUM(curr_total-curr_leads_changed) OVER()/SUM(curr_open) OVER())*100) BIM_GRAND_TOTAL7,
SUM(leads_closed) OVER() BIM_GRAND_TOTAL8,
SUM(leads_converted) OVER() BIM_GRAND_TOTAL9
FROM
(
select BIM_SALES_GROUP,
VIEWBYID,
leaf_node_flag,
sum(prior_open) prior_open,
sum(curr_open) curr_open,
sum(curr_total) curr_total,
sum(leads_converted) leads_converted,
sum(leads_new) leads_new,
sum(leads_dead) leads_dead,
sum(leads_closed) leads_closed,
sum(curr_leads_changed) curr_leads_changed
FROM
(
select /*+ ORDERED */
p.value BIM_SALES_GROUP,
p.parent_id VIEWBYID,
p.leaf_node_flag leaf_node_flag,
SUM(case when c.report_date=&BIS_CURRENT_EFFECTIVE_START_DATE - 1 and &BIS_CURRENT_EFFECTIVE_START_DATE<> :g_start_date then b.leads-(b.leads_closed+b.leads_dead+b.leads_converted) else 0 end) prior_open,
SUM(case when c.report_date=&BIS_CURRENT_ASOF_DATE then b.leads-(b.leads_closed+b.leads_dead+b.leads_converted) else 0 end) curr_open,
SUM(case when c.report_date=&BIS_CURRENT_ASOF_DATE then b.leads else 0 end) curr_total,
0 leads_converted,
0 leads_new,
0 leads_dead,
0 leads_closed,
SUM(case when c.report_date=&BIS_CURRENT_ASOF_DATE then b.leads_changed else 0 end) curr_leads_changed
FROM FII_TIME_RPT_STRUCT c, BIM_I_LP_GEN_SG_MV b,
( SELECT e.parent_id parent_id ,e.value value,e.leaf_node_flag leaf_node_flag
FROM eni_item_vbh_nodes_v e
WHERE e.top_node_flag=''Y''
AND e.child_id = e.parent_id) p
,eni_denorm_hierarchies edh
,mtl_default_category_sets d
WHERE
b.group_id =:l_group_id
AND b.product_category_id = edh.child_id
AND edh.object_type = ''CATEGORY_SET''
AND edh.object_id = d.category_set_id
AND d.functional_area_id = 11
AND edh.dbi_flag = ''Y''
AND edh.parent_id = p.parent_id
AND c.calendar_id=-1
AND c.report_date in (&BIS_CURRENT_ASOF_DATE,&BIS_CURRENT_EFFECTIVE_START_DATE - 1)
AND BITAND(c.record_type_id,1143)=c.record_type_id
AND b.time_id=c.time_id
AND b.period_type_id=c.period_type_id
AND b.update_period_type_id = -1
AND b.update_time_id = -1
AND b.resource_id = :l_resource_id
GROUP BY p.value,p.parent_id,p.leaf_node_flag
UNION ALL
/*Others for sales group*/
select /*+ ORDERED */
p.value BIM_SALES_GROUP,
p.parent_id VIEWBYID,
p.leaf_node_flag leaf_node_flag,
0 prior_open,
0 curr_open,
0 curr_total,
sum(leads_converted) leads_converted,
sum(leads_new) leads_new,
sum(leads_dead) leads_dead,
sum(leads_closed) leads_closed,
0 curr_leads_changed
FROM FII_TIME_RPT_STRUCT c, BIM_I_LP_GEN_SG_MV b,
( SELECT e.parent_id parent_id ,e.value value,e.leaf_node_flag leaf_node_flag
FROM eni_item_vbh_nodes_v e
WHERE e.top_node_flag=''Y''
AND e.child_id = e.parent_id) p
,eni_denorm_hierarchies edh
,mtl_default_category_sets d
WHERE
b.group_id =:l_group_id
AND b.product_category_id = edh.child_id
AND edh.object_type = ''CATEGORY_SET''
AND edh.object_id = d.category_set_id
AND d.functional_area_id = 11
AND edh.dbi_flag = ''Y''
AND edh.parent_id = p.parent_id
AND c.calendar_id=-1
AND c.report_date = &BIS_CURRENT_ASOF_DATE
AND BITAND(c.record_type_id,:l_record_type)=c.record_type_id
AND b.time_id=c.time_id
AND b.period_type_id=c.period_type_id
AND b.update_period_type_id = -1
AND b.update_time_id = -1
AND b.resource_id = :l_resource_id
AND ( leads_converted <> 0 or leads_new <> 0 or leads_dead <> 0 or leads_closed <> 0 )
GROUP BY p.value,p.parent_id,p.leaf_node_flag
)
GROUP BY BIM_SALES_GROUP,VIEWBYID,leaf_node_flag
HAVING
sum(prior_open) > 0
OR sum(leads_new) > 0
OR sum(leads_converted) > 0
OR sum(leads_dead) > 0
OR sum(curr_open) > 0
OR sum(curr_total)-sum(curr_leads_changed) > 0
OR sum(leads_closed) > 0
) &ORDER_BY_CLAUSE';
'SELECT BIM_SALES_GROUP VIEWBY,
VIEWBYID,
prior_open BIM_MEASURE1,
leads_new BIM_MEASURE2,
leads_converted BIM_MEASURE3,
leads_dead BIM_MEASURE4,
curr_open BIM_MEASURE5,
curr_total-curr_leads_changed BIM_MEASURE6,
leads_closed BIM_MEASURE8,
DECODE(curr_open,0,0,((curr_total-curr_leads_changed)/curr_open)*100) BIM_MEASURE7,
leads_converted BIM_MEASURE9,
NULL BIM_URL1,
DECODE(leaf_node_flag,''Y'',NULL,'||''''||l_url_str||''''||' ) BIM_URL2,
CASE WHEN VIEWBYID = -1 THEN NULL WHEN dir_flag = 1 THEN NULL WHEN leads_new =0 THEN NULL
ELSE '||''''||l_url_str1||''''||'||'||''''||l_Metric_a||''''||'||'||''''||l_rpt_name||''''||'||VIEWBYID'||'||'||''''||l_context_info||' END BIM_URL3,
CASE WHEN VIEWBYID = -1 THEN NULL WHEN dir_flag = 1 THEN NULL WHEN leads_converted = 0 THEN NULL ELSE
'||''''||l_url_str2||''''||'||'||''''||l_Metric_b||''''||'||'||''''||l_rpt_name||''''||'||VIEWBYID'||'||'||''''||l_context_info||' END BIM_URL4,
CASE WHEN VIEWBYID = -1 THEN NULL WHEN dir_flag = 1 THEN NULL WHEN leads_closed = 0 THEN NULL ELSE
'||''''||l_url_str3||''''||'||'||''''||l_Metric_c||''''||'||'||''''||l_rpt_name||''''||'||VIEWBYID'||'||'||''''||l_context_info||' END BIM_URL5,
CASE WHEN VIEWBYID = -1 THEN NULL WHEN dir_flag = 1 THEN NULL WHEN curr_open = 0 THEN NULL ELSE
'||''''||l_url_str4||''''||'||'||''''||l_Metric_d||''''||'||'||''''||l_rpt_name||''''||'||VIEWBYID'||'||'||''''||l_context_info||' END BIM_URL6,
CASE WHEN VIEWBYID = -1 THEN NULL WHEN dir_flag = 1 THEN NULL WHEN (curr_total-curr_leads_changed) = 0 THEN NULL ELSE
'||''''||l_url_str5||''''||'||'||''''||l_Metric_e||''''||'||'||''''||l_rpt_name||''''||'||VIEWBYID'||'||'||''''||l_context_info||' END BIM_URL7,
SUM(prior_open) OVER() BIM_GRAND_TOTAL1,SUM(leads_new) OVER() BIM_GRAND_TOTAL2,SUM(leads_converted) OVER() BIM_GRAND_TOTAL3,SUM(leads_dead) OVER() BIM_GRAND_TOTAL4,
SUM(curr_open) OVER() BIM_GRAND_TOTAL5,SUM(curr_total-curr_leads_changed) OVER() BIM_GRAND_TOTAL6,
DECODE(SUM(curr_open) OVER(),0,0,(SUM(curr_total-curr_leads_changed) OVER()/SUM(curr_open) OVER())*100) BIM_GRAND_TOTAL7,
SUM(leads_closed) OVER() BIM_GRAND_TOTAL8,
SUM(leads_converted) OVER() BIM_GRAND_TOTAL9
FROM
( select BIM_SALES_GROUP,VIEWBYID,leaf_node_flag,dir_flag,sum(prior_open) prior_open,sum(curr_open) curr_open,sum(curr_total) curr_total,
sum(leads_converted) leads_converted,sum(leads_new) leads_new,sum(leads_dead) leads_dead,sum(leads_closed) leads_closed,sum(curr_leads_changed) curr_leads_changed
FROM
(
/*********children of the selected category*********/
select /*+ ORDERED */
p.value BIM_SALES_GROUP,p.id VIEWBYID,p.leaf_node_flag leaf_node_flag,0 dir_flag,
SUM(case when c.report_date=&BIS_CURRENT_EFFECTIVE_START_DATE - 1 and &BIS_CURRENT_EFFECTIVE_START_DATE<> :g_start_date then b.leads-(b.leads_closed+b.leads_dead+b.leads_converted) else 0 end) prior_open,
SUM(case when c.report_date=&BIS_CURRENT_ASOF_DATE then b.leads-(b.leads_closed+b.leads_dead+b.leads_converted) else 0 end) curr_open,
SUM(case when c.report_date=&BIS_CURRENT_ASOF_DATE then b.leads else 0 end) curr_total,
0 leads_converted,0 leads_new,0 leads_dead,0 leads_closed,SUM(case when c.report_date=&BIS_CURRENT_ASOF_DATE then b.leads_changed else 0 end) curr_leads_changed
FROM FII_TIME_RPT_STRUCT c,BIM_I_LP_GEN_SG_MV b
,eni_denorm_hierarchies edh
,mtl_default_category_sets mdc
,(SELECT e.id,e.value,leaf_node_flag
FROM eni_item_vbh_nodes_v e
WHERE e.parent_id =&ITEM+ENI_ITEM_VBH_CAT
AND e.id = e.child_id
AND ((e.leaf_node_flag=''N'' AND e.parent_id<>e.id) OR e.leaf_node_flag=''Y'')
) p
WHERE
b.group_id=&ORGANIZATION+JTF_ORG_SALES_GROUP
AND b.product_category_id = edh.child_id
AND edh.object_type = ''CATEGORY_SET''
AND edh.object_id = mdc.category_set_id
AND mdc.functional_area_id = 11
AND edh.dbi_flag = ''Y''
AND edh.parent_id = p.id
AND c.calendar_id=-1
AND c.report_date in (&BIS_CURRENT_ASOF_DATE,&BIS_CURRENT_EFFECTIVE_START_DATE - 1)
AND BITAND(c.record_type_id,1143)=c.record_type_id
AND b.time_id=c.time_id
AND b.period_type_id=c.period_type_id
AND b.update_period_type_id = -1
AND b.update_time_id = -1
AND b.resource_id = :l_resource_id
GROUP BY p.value,p.id,p.leaf_node_flag
UNION ALL
/*Others for sales group*/
select /*+ ORDERED */
p.value BIM_SALES_GROUP,p.id VIEWBYID,p.leaf_node_flag leaf_node_flag,0 dir_flag,0 prior_open,0 curr_open,0 curr_total,
sum(leads_converted) leads_converted,sum(leads_new) leads_new,sum(leads_dead) leads_dead,sum(leads_closed) leads_closed,0 curr_leads_changed
FROM FII_TIME_RPT_STRUCT c, BIM_I_LP_GEN_SG_MV b
,eni_denorm_hierarchies edh
,mtl_default_category_sets mdc
,(SELECT e.id,e.value,leaf_node_flag
FROM eni_item_vbh_nodes_v e
WHERE e.parent_id =&ITEM+ENI_ITEM_VBH_CAT
AND e.id = e.child_id
AND ((e.leaf_node_flag=''N'' AND e.parent_id<>e.id) OR e.leaf_node_flag=''Y'')
) p
WHERE
b.group_id=&ORGANIZATION+JTF_ORG_SALES_GROUP
AND b.product_category_id = edh.child_id
AND edh.object_type = ''CATEGORY_SET''
AND edh.object_id = mdc.category_set_id
AND mdc.functional_area_id = 11
AND edh.dbi_flag = ''Y''
AND edh.parent_id = p.id
AND c.calendar_id=-1
AND c.report_date = &BIS_CURRENT_ASOF_DATE
AND BITAND(c.record_type_id,:l_record_type)=c.record_type_id
AND b.time_id=c.time_id
AND b.period_type_id=c.period_type_id
AND b.update_period_type_id = -1
AND b.update_time_id = -1
AND b.resource_id = :l_resource_id
AND ( leads_converted <> 0 or leads_new <> 0 or leads_dead <> 0 or leads_closed <> 0 )
GROUP BY p.value,p.id,p.leaf_node_flag
UNION ALL
/******Directly Assigned to Category*******/
select /*+ ORDERED */
bim_pmv_dbi_utl_pkg.get_lookup_value('||''''||'DASS'||''''||')'||' BIM_SALES_GROUP,p.id VIEWBYID,''Y'' leaf_node_flag,1 dir_flag,
SUM(case when c.report_date=&BIS_CURRENT_EFFECTIVE_START_DATE - 1 and &BIS_CURRENT_EFFECTIVE_START_DATE<> :g_start_date then b.leads-(b.leads_closed+b.leads_dead+b.leads_converted) else 0 end) prior_open,
SUM(case when c.report_date=&BIS_CURRENT_ASOF_DATE then b.leads-(b.leads_closed+b.leads_dead+b.leads_converted) else 0 end) curr_open,
SUM(case when c.report_date=&BIS_CURRENT_ASOF_DATE then b.leads else 0 end) curr_total,
0 leads_converted,0 leads_new,0 leads_dead,0 leads_closed,SUM(case when c.report_date=&BIS_CURRENT_ASOF_DATE then b.leads_changed else 0 end) curr_leads_changed
FROM FII_TIME_RPT_STRUCT c, BIM_I_LP_GEN_SG_MV b
,(SELECT e.id id,e.value value
FROM eni_item_vbh_nodes_v e
WHERE e.parent_id = &ITEM+ENI_ITEM_VBH_CAT
AND e.parent_id = e.child_id
AND leaf_node_flag <> ''Y''
) p
WHERE
b.group_id=&ORGANIZATION+JTF_ORG_SALES_GROUP
AND p.id = b.product_category_id
AND c.calendar_id=-1
AND c.report_date in (&BIS_CURRENT_ASOF_DATE,&BIS_CURRENT_EFFECTIVE_START_DATE - 1)
AND BITAND(c.record_type_id,1143)=c.record_type_id
AND b.time_id=c.time_id
AND b.period_type_id=c.period_type_id
AND b.update_period_type_id = -1
AND b.update_time_id = -1
and b.item_id = ''-1''
AND b.resource_id = :l_resource_id
GROUP BY p.value,p.id
UNION ALL
/*Others for sales group*/
select /*+ ORDERED */
bim_pmv_dbi_utl_pkg.get_lookup_value('||''''||'DASS'||''''||')'||' BIM_SALES_GROUP,p.id VIEWBYID,''Y'' leaf_node_flag,1 dir_flag,
0 prior_open,0 curr_open,0 curr_total,sum(leads_converted) leads_converted,sum(leads_new) leads_new,sum(leads_dead) leads_dead,sum(leads_closed) leads_closed,
0 curr_leads_changed
FROM FII_TIME_RPT_STRUCT c, BIM_I_LP_GEN_SG_MV b
,(SELECT e.id id,e.value value
FROM eni_item_vbh_nodes_v e
WHERE e.parent_id = &ITEM+ENI_ITEM_VBH_CAT
AND e.parent_id = e.child_id
AND leaf_node_flag <> ''Y''
) p
WHERE
b.group_id=&ORGANIZATION+JTF_ORG_SALES_GROUP
AND p.id = b.product_category_id
AND c.calendar_id=-1
AND c.report_date = &BIS_CURRENT_ASOF_DATE
AND BITAND(c.record_type_id,:l_record_type)=c.record_type_id
AND b.time_id=c.time_id
AND b.period_type_id=c.period_type_id
AND b.update_period_type_id = -1
AND b.update_time_id = -1
and b.item_id = ''-1''
AND b.resource_id = :l_resource_id
AND ( leads_converted <> 0 or leads_new <> 0 or leads_dead <> 0 or leads_closed <> 0 )
GROUP BY p.value,p.id
)
GROUP BY BIM_SALES_GROUP,VIEWBYID,leaf_node_flag,dir_flag
HAVING
sum(prior_open) > 0 OR sum(leads_new) > 0 OR sum(leads_converted) > 0 OR sum(leads_dead) > 0 OR sum(curr_open) > 0
OR sum(curr_total)-sum(curr_leads_changed) > 0 OR sum(leads_closed) > 0
) &ORDER_BY_CLAUSE';
'SELECT BIM_SALES_GROUP VIEWBY,
VIEWBYID,
prior_open BIM_MEASURE1,leads_new BIM_MEASURE2,leads_converted BIM_MEASURE3,leads_dead BIM_MEASURE4,curr_open BIM_MEASURE5,
curr_total-curr_leads_changed BIM_MEASURE6,leads_closed BIM_MEASURE8,DECODE(curr_open,0,0,((curr_total-curr_leads_changed)/curr_open)*100) BIM_MEASURE7,
leads_converted BIM_MEASURE9, NULL BIM_URL1,
DECODE(leaf_node_flag,''Y'',NULL,'||''''||l_url_str||''''||' ) BIM_URL2,
CASE WHEN VIEWBYID = -1 THEN null WHEN dir_flag=1 THEN NULL WHEN leads_new=0 THEN NULL ELSE '||''''||l_url_str1||''''||'||'||''''||l_Metric_a||''''||'||'||''''||l_rpt_name||''''||'||VIEWBYID'||'||'||''''||l_context_info||' END BIM_URL3,
CASE WHEN VIEWBYID = -1 THEN null WHEN dir_flag=1 THEN NULL WHEN leads_converted=0 THEN NULL ELSE '||''''||l_url_str2||''''||'||'||''''||l_Metric_b||''''||'||'||''''||l_rpt_name||''''||'||VIEWBYID'||'||'||''''||l_context_info||' END BIM_URL4,
CASE WHEN VIEWBYID = -1 THEN null WHEN dir_flag=1 THEN NULL WHEN leads_closed=0 THEN NULL ELSE '||''''||l_url_str3||''''||'||'||''''||l_Metric_c||''''||'||'||''''||l_rpt_name||''''||'||VIEWBYID'||'||'||''''||l_context_info||' END BIM_URL5,
CASE WHEN VIEWBYID = -1 THEN null WHEN dir_flag=1 THEN NULL WHEN curr_open= 0 THEN NULL ELSE'||''''||l_url_str4||''''||'||'||''''||l_Metric_d||''''||'||'||''''||l_rpt_name||''''||'||VIEWBYID'||'||'||''''||l_context_info||' END BIM_URL6,
CASE WHEN VIEWBYID = -1 THEN null WHEN dir_flag=1 THEN NULL WHEN(curr_total-curr_leads_changed)= 0 THEN NULL
ELSE '||''''||l_url_str5||''''||'||'||''''||l_Metric_e||''''||'||'||''''||l_rpt_name||''''||'||VIEWBYID'||'||'||''''||l_context_info||' END BIM_URL7,
SUM(prior_open) OVER() BIM_GRAND_TOTAL1,SUM(leads_new) OVER() BIM_GRAND_TOTAL2,SUM(leads_converted) OVER() BIM_GRAND_TOTAL3,
SUM(leads_dead) OVER() BIM_GRAND_TOTAL4,SUM(curr_open) OVER() BIM_GRAND_TOTAL5,SUM(curr_total-curr_leads_changed) OVER() BIM_GRAND_TOTAL6,
DECODE(SUM(curr_open) OVER(),0,0,(SUM(curr_total-curr_leads_changed) OVER()/SUM(curr_open) OVER())*100) BIM_GRAND_TOTAL7,
SUM(leads_closed) OVER() BIM_GRAND_TOTAL8,SUM(leads_converted) OVER() BIM_GRAND_TOTAL9
FROM
( select BIM_SALES_GROUP,VIEWBYID,leaf_node_flag,dir_flag,sum(prior_open) prior_open,sum(curr_open) curr_open,sum(curr_total) curr_total,
sum(leads_converted) leads_converted,sum(leads_new) leads_new,sum(leads_dead) leads_dead,sum(leads_closed) leads_closed,sum(curr_leads_changed) curr_leads_changed
FROM
( select /*+ ORDERED */ p.value BIM_SALES_GROUP,p.id VIEWBYID,p.leaf_node_flag leaf_node_flag,0 dir_flag,
SUM(case when c.report_date=&BIS_CURRENT_EFFECTIVE_START_DATE - 1 and &BIS_CURRENT_EFFECTIVE_START_DATE<> :g_start_date then b.leads-(b.leads_closed+b.leads_dead+b.leads_converted) else 0 end) prior_open,
SUM(case when c.report_date=&BIS_CURRENT_ASOF_DATE then b.leads-(b.leads_closed+b.leads_dead+b.leads_converted) else 0 end) curr_open,
SUM(case when c.report_date=&BIS_CURRENT_ASOF_DATE then b.leads else 0 end) curr_total,
0 leads_converted,0 leads_new,0 leads_dead,0 leads_closed,
SUM(case when c.report_date=&BIS_CURRENT_ASOF_DATE then b.leads_changed else 0 end) curr_leads_changed
FROM FII_TIME_RPT_STRUCT c, BIM_I_LP_GEN_SG_MV b
,eni_denorm_hierarchies edh
,mtl_default_category_sets mdc
,(SELECT e.id,e.value,leaf_node_flag
FROM eni_item_vbh_nodes_v e
WHERE e.parent_id =&ITEM+ENI_ITEM_VBH_CAT
AND e.id = e.child_id
AND ((e.leaf_node_flag=''N'' AND e.parent_id<>e.id) OR e.leaf_node_flag=''Y'')
) p
WHERE
b.group_id=:l_group_id
AND b.product_category_id = edh.child_id
AND edh.object_type = ''CATEGORY_SET''
AND edh.object_id = mdc.category_set_id
AND mdc.functional_area_id = 11
AND edh.dbi_flag = ''Y''
AND edh.parent_id = p.id
AND c.calendar_id=-1
AND c.report_date in (&BIS_CURRENT_ASOF_DATE,&BIS_CURRENT_EFFECTIVE_START_DATE - 1)
AND BITAND(c.record_type_id,1143)=c.record_type_id
AND b.time_id=c.time_id
AND b.period_type_id=c.period_type_id
AND b.update_period_type_id = -1
AND b.update_time_id = -1
AND b.resource_id = :l_resource_id
GROUP BY p.value,p.id,p.leaf_node_flag
UNION ALL
select /*+ ORDERED */ p.value BIM_SALES_GROUP,p.id VIEWBYID,p.leaf_node_flag leaf_node_flag,0 dir_flag,
0 prior_open,0 curr_open,0 curr_total,sum(leads_converted) leads_converted,sum(leads_new) leads_new,
sum(leads_dead) leads_dead,sum(leads_closed) leads_closed,0 curr_leads_changed
FROM FII_TIME_RPT_STRUCT c, BIM_I_LP_GEN_SG_MV b
,eni_denorm_hierarchies edh
,mtl_default_category_sets mdc
,(SELECT e.id,e.value,leaf_node_flag
FROM eni_item_vbh_nodes_v e
WHERE e.parent_id =&ITEM+ENI_ITEM_VBH_CAT
AND e.id = e.child_id
AND ((e.leaf_node_flag=''N'' AND e.parent_id<>e.id) OR e.leaf_node_flag=''Y'')
) p
WHERE
b.group_id=:l_group_id
AND b.product_category_id = edh.child_id
AND edh.object_type = ''CATEGORY_SET''
AND edh.object_id = mdc.category_set_id
AND mdc.functional_area_id = 11
AND edh.dbi_flag = ''Y''
AND edh.parent_id = p.id
AND c.calendar_id=-1
AND c.report_date = &BIS_CURRENT_ASOF_DATE
AND BITAND(c.record_type_id,:l_record_type)=c.record_type_id
AND b.time_id=c.time_id
AND b.period_type_id=c.period_type_id
AND b.update_period_type_id = -1
AND b.update_time_id = -1
AND b.resource_id =:l_resource_id
AND ( leads_converted <> 0 or leads_new <> 0 or leads_dead <> 0 or leads_closed <> 0 )
GROUP BY p.value,p.id,p.leaf_node_flag
UNION ALL
select /*+ ORDERED */
bim_pmv_dbi_utl_pkg.get_lookup_value('||''''||'DASS'||''''||')'||' BIM_SALES_GROUP,
p.id VIEWBYID,''Y'' leaf_node_flag,1 dir_flag,
SUM(case when c.report_date=&BIS_CURRENT_EFFECTIVE_START_DATE - 1 and &BIS_CURRENT_EFFECTIVE_START_DATE<> :g_start_date then b.leads-(b.leads_closed+b.leads_dead+b.leads_converted) else 0 end) prior_open,
SUM(case when c.report_date=&BIS_CURRENT_ASOF_DATE then b.leads-(b.leads_closed+b.leads_dead+b.leads_converted) else 0 end) curr_open,
SUM(case when c.report_date=&BIS_CURRENT_ASOF_DATE then b.leads else 0 end) curr_total,
0 leads_converted,0 leads_new,0 leads_dead,0 leads_closed,SUM(case when c.report_date=&BIS_CURRENT_ASOF_DATE then b.leads_changed else 0 end) curr_leads_changed
FROM FII_TIME_RPT_STRUCT c, BIM_I_LP_GEN_SG_MV b
,(SELECT e.id id,e.value value
FROM eni_item_vbh_nodes_v e
WHERE e.parent_id = &ITEM+ENI_ITEM_VBH_CAT
AND e.parent_id = e.child_id
AND leaf_node_flag <> ''Y''
) p
WHERE
b.group_id=:l_group_id
AND p.id = b.product_category_id
AND c.calendar_id=-1
AND c.report_date in (&BIS_CURRENT_ASOF_DATE,&BIS_CURRENT_EFFECTIVE_START_DATE - 1)
AND BITAND(c.record_type_id,1143)=c.record_type_id
AND b.time_id=c.time_id
AND b.period_type_id=c.period_type_id
AND b.update_period_type_id = -1
AND b.update_time_id = -1
and b.item_id = ''-1''
AND b.resource_id =:l_resource_id
GROUP BY p.value,p.id
UNION ALL
select /*+ ORDERED */
bim_pmv_dbi_utl_pkg.get_lookup_value('||''''||'DASS'||''''||')'||' BIM_SALES_GROUP,
p.id VIEWBYID,''Y'' leaf_node_flag,1 dir_flag,0 prior_open,0 curr_open,0 curr_total,
sum(leads_converted) leads_converted,sum(leads_new) leads_new,sum(leads_dead) leads_dead,
sum(leads_closed) leads_closed,0 curr_leads_changed
FROM FII_TIME_RPT_STRUCT c,BIM_I_LP_GEN_SG_MV b
,(SELECT e.id id,e.value value
FROM eni_item_vbh_nodes_v e
WHERE e.parent_id = &ITEM+ENI_ITEM_VBH_CAT
AND e.parent_id = e.child_id
AND leaf_node_flag <> ''Y''
) p
WHERE
b.group_id=:l_group_id
AND p.id = b.product_category_id
AND c.calendar_id=-1
AND c.report_date = &BIS_CURRENT_ASOF_DATE
AND BITAND(c.record_type_id,:l_record_type)=c.record_type_id
AND b.time_id=c.time_id
AND b.period_type_id=c.period_type_id
AND b.update_period_type_id = -1
AND b.update_time_id = -1
and b.item_id = ''-1''
AND b.resource_id = :l_resource_id
AND ( leads_converted <> 0 or leads_new <> 0 or leads_dead <> 0 or leads_closed <> 0 )
GROUP BY p.value,p.id
)
GROUP BY BIM_SALES_GROUP,VIEWBYID,leaf_node_flag,dir_flag
HAVING sum(prior_open) > 0 OR sum(leads_new) > 0 OR sum(leads_converted) > 0
OR sum(leads_dead) > 0 OR sum(curr_open) > 0 OR sum(curr_total)-sum(curr_leads_changed) > 0 OR sum(leads_closed) > 0
) &ORDER_BY_CLAUSE';
AND b.update_time_id=-1
AND b.update_period_type_id =-1
AND b.resource_id = :l_resource_id ';
AND b.update_time_id= -1
AND b.update_period_type_id= -1
AND b.resource_id = :l_resource_id ';
AND b.update_time_id=-1
AND b.update_period_type_id=-1
AND b.resource_id =:l_resource_id ';
AND b.update_time_id=-1
AND b.update_period_type_id=-1
AND b.resource_id =:l_resource_id ';
AND b.update_time_id=-1
AND b.update_period_type_id =-1
AND b.resource_id = :l_resource_id
AND b.product_category_id = edh.child_id AND edh.object_type = ''CATEGORY_SET'' AND edh.object_id = mtl.category_set_id
AND mtl.functional_area_id = 11 AND edh.dbi_flag = ''Y'' AND edh.parent_id = &ITEM+ENI_ITEM_VBH_CAT ';
AND b.update_time_id=-1
AND b.update_period_type_id=-1
AND b.resource_id = :l_resource_id
AND b.product_category_id = edh.child_id AND edh.object_type = ''CATEGORY_SET'' AND edh.object_id = mtl.category_set_id
AND mtl.functional_area_id = 11 AND edh.dbi_flag = ''Y'' AND edh.parent_id = &ITEM+ENI_ITEM_VBH_CAT ';
AND b.update_time_id=-1
AND b.update_period_type_id=-1
AND b.resource_id =:l_resource_id
AND b.product_category_id = edh.child_id AND edh.object_type = ''CATEGORY_SET'' AND edh.object_id = mtl.category_set_id
AND mtl.functional_area_id = 11 AND edh.dbi_flag = ''Y'' AND edh.parent_id = &ITEM+ENI_ITEM_VBH_CAT ';
AND b.update_time_id=-1
AND b.update_period_type_id=-1
AND b.resource_id =:l_resource_id
AND b.product_category_id = edh.child_id AND edh.object_type = ''CATEGORY_SET'' AND edh.object_id = mtl.category_set_id
AND mtl.functional_area_id = 11 AND edh.dbi_flag = ''Y'' AND edh.parent_id = &ITEM+ENI_ITEM_VBH_CAT ';
AND b.update_time_id=-1
AND b.update_period_type_id =-1
AND b.resource_id = :l_resource_id ';
AND b.update_time_id=-1
AND b.update_period_type_id=-1
AND b.resource_id =:l_resource_id ';
AND b.update_time_id=-1
AND b.update_period_type_id=-1
AND b.resource_id =:l_resource_id ';
AND b.update_time_id=-1
AND b.update_period_type_id=-1
AND b.resource_id =:l_resource_id ';
AND b.update_time_id=-1
AND b.update_period_type_id =-1
AND b.resource_id = :l_resource_id
AND b.product_category_id = edh.child_id AND edh.object_type = ''CATEGORY_SET'' AND edh.object_id = mtl.category_set_id
AND mtl.functional_area_id = 11 AND edh.dbi_flag = ''Y'' AND edh.parent_id = &ITEM+ENI_ITEM_VBH_CAT ';
AND b.update_time_id=-1
AND b.update_period_type_id=-1
AND b.resource_id =:l_resource_id
AND b.product_category_id = edh.child_id AND edh.object_type = ''CATEGORY_SET'' AND edh.object_id = mtl.category_set_id
AND mtl.functional_area_id = 11 AND edh.dbi_flag = ''Y'' AND edh.parent_id = &ITEM+ENI_ITEM_VBH_CAT ';
AND b.update_time_id=-1
AND b.update_period_type_id=-1
AND b.resource_id =:l_resource_id
AND b.product_category_id = edh.child_id AND edh.object_type = ''CATEGORY_SET'' AND edh.object_id = mtl.category_set_id
AND mtl.functional_area_id = 11 AND edh.dbi_flag = ''Y'' AND edh.parent_id = &ITEM+ENI_ITEM_VBH_CAT ';
AND b.update_time_id=-1
AND b.update_period_type_id=-1
AND b.resource_id =:l_resource_id
AND b.product_category_id = edh.child_id AND edh.object_type = ''CATEGORY_SET'' AND edh.object_id = mtl.category_set_id
AND mtl.functional_area_id = 11 AND edh.dbi_flag = ''Y'' AND edh.parent_id = &ITEM+ENI_ITEM_VBH_CAT ';
AND b.update_time_id=-1
AND b.update_period_type_id =-1
AND b.resource_id =:l_resource_id ';
AND b.update_time_id=-1
AND b.update_period_type_id=-1
AND b.resource_id = :l_resource_id ';
AND b.update_time_id=-1
AND b.update_period_type_id=-1
AND b.resource_id =:l_resource_id ';
AND b.update_time_id=-1
AND b.update_period_type_id=-1
AND b.resource_id =:l_resource_id ';
AND b.update_time_id=-1
AND b.update_period_type_id =-1
AND b.resource_id = :l_resource_id
AND b.product_category_id = edh.child_id AND edh.object_type = ''CATEGORY_SET'' AND edh.object_id = mtl.category_set_id
AND mtl.functional_area_id = 11 AND edh.dbi_flag = ''Y'' AND edh.parent_id = &ITEM+ENI_ITEM_VBH_CAT ';
AND b.update_time_id=-1
AND b.update_period_type_id=-1
AND b.resource_id = :l_resource_id
AND b.product_category_id = edh.child_id AND edh.object_type = ''CATEGORY_SET'' AND edh.object_id = mtl.category_set_id
AND mtl.functional_area_id = 11 AND edh.dbi_flag = ''Y'' AND edh.parent_id = &ITEM+ENI_ITEM_VBH_CAT ';
AND b.update_time_id=-1
AND b.update_period_type_id=-1
AND b.resource_id = :l_resource_id
AND b.product_category_id = edh.child_id AND edh.object_type = ''CATEGORY_SET'' AND edh.object_id = mtl.category_set_id
AND mtl.functional_area_id = 11 AND edh.dbi_flag = ''Y'' AND edh.parent_id = &ITEM+ENI_ITEM_VBH_CAT ';
AND b.update_time_id=-1
AND b.update_period_type_id=-1
AND b.resource_id =:l_resource_id
AND b.product_category_id = edh.child_id AND edh.object_type = ''CATEGORY_SET'' AND edh.object_id = mtl.category_set_id
AND mtl.functional_area_id = 11 AND edh.dbi_flag = ''Y'' AND edh.parent_id = &ITEM+ENI_ITEM_VBH_CAT ';
AND b.update_time_id=-1
AND b.update_period_type_id =-1
AND b.resource_id = :l_resource_id ';
AND b.update_time_id=-1
AND b.update_period_type_id=-1
AND b.resource_id =:l_resource_id ';
AND b.update_time_id=-1
AND b.update_period_type_id=-1
AND b.resource_id =:l_resource_id';
AND b.update_time_id=-1
AND b.update_period_type_id=-1
AND b.resource_id =:l_resource_id ';
AND b.update_time_id=-1
AND b.update_period_type_id =-1
AND b.resource_id = :l_resource_id
AND b.product_category_id = edh.child_id AND edh.object_type = ''CATEGORY_SET'' AND edh.object_id = mtl.category_set_id
AND mtl.functional_area_id = 11 AND edh.dbi_flag = ''Y'' AND edh.parent_id = &ITEM+ENI_ITEM_VBH_CAT ';
AND b.update_time_id=-1
AND b.update_period_type_id=-1
AND b.resource_id = :l_resource_id
AND b.product_category_id = edh.child_id AND edh.object_type = ''CATEGORY_SET'' AND edh.object_id = mtl.category_set_id
AND mtl.functional_area_id = 11 AND edh.dbi_flag = ''Y'' AND edh.parent_id = &ITEM+ENI_ITEM_VBH_CAT ';
AND b.update_time_id=-1
AND b.update_period_type_id=-1
AND b.resource_id =:l_resource_id
AND b.product_category_id = edh.child_id AND edh.object_type = ''CATEGORY_SET'' AND edh.object_id = mtl.category_set_id
AND mtl.functional_area_id = 11 AND edh.dbi_flag = ''Y'' AND edh.parent_id = &ITEM+ENI_ITEM_VBH_CAT ';
AND b.update_time_id=-1
AND b.update_period_type_id=-1
AND b.resource_id =:l_resource_id
AND b.product_category_id = edh.child_id AND edh.object_type = ''CATEGORY_SET'' AND edh.object_id = mtl.category_set_id
AND mtl.functional_area_id = 11 AND edh.dbi_flag = ''Y'' AND edh.parent_id = &ITEM+ENI_ITEM_VBH_CAT ';
AND b.update_time_id=-1
AND b.update_period_type_id =-1
AND b.resource_id = :l_resource_id ';
AND b.update_time_id=-1
AND b.update_period_type_id=-1
AND b.resource_id = :l_resource_id ';
AND b.update_time_id=-1
AND b.update_period_type_id=-1
AND b.resource_id =:l_resource_id ';
AND b.update_time_id=-1
AND b.update_period_type_id=-1
AND b.resource_id =:l_resource_id ';
AND b.update_time_id=-1
AND b.update_period_type_id =-1
AND b.resource_id = :l_resource_id
AND b.product_category_id = edh.child_id AND edh.object_type = ''CATEGORY_SET'' AND edh.object_id = mtl.category_set_id
AND mtl.functional_area_id = 11 AND edh.dbi_flag = ''Y'' AND edh.parent_id = &ITEM+ENI_ITEM_VBH_CAT ';
AND b.update_time_id=-1
AND b.update_period_type_id=-1
AND b.resource_id = :l_resource_id
AND b.product_category_id = edh.child_id AND edh.object_type = ''CATEGORY_SET'' AND edh.object_id = mtl.category_set_id
AND mtl.functional_area_id = 11 AND edh.dbi_flag = ''Y'' AND edh.parent_id = &ITEM+ENI_ITEM_VBH_CAT ';
AND b.update_time_id=-1
AND b.update_period_type_id=-1
AND b.resource_id =:l_resource_id
AND b.product_category_id = edh.child_id AND edh.object_type = ''CATEGORY_SET'' AND edh.object_id = mtl.category_set_id
AND mtl.functional_area_id = 11 AND edh.dbi_flag = ''Y'' AND edh.parent_id = &ITEM+ENI_ITEM_VBH_CAT ';
AND b.update_time_id=-1
AND b.update_period_type_id=-1
AND b.resource_id =:l_resource_id
AND b.product_category_id = edh.child_id AND edh.object_type = ''CATEGORY_SET'' AND edh.object_id = mtl.category_set_id
AND mtl.functional_area_id = 11 AND edh.dbi_flag = ''Y'' AND edh.parent_id = &ITEM+ENI_ITEM_VBH_CAT ';
SELECT a.source_name BIM_SALES_GROUP,VIEWBYID,is_resource,prior_open,curr_open,curr_total,
leads_converted,leads_new,leads_dead,leads_closed,curr_leads_changed from (
/*Prior Open and Current Open for reps*/
SELECT '||l_hint||' '||l_col1_b||' resource_id,
'||l_col2_b||' VIEWBYID,
'||l_col3_b||' is_resource,
SUM(case when c.report_date=&BIS_CURRENT_EFFECTIVE_START_DATE - 1 and &BIS_CURRENT_EFFECTIVE_START_DATE<> :g_start_date then b.leads-(b.leads_closed+b.leads_dead+b.leads_converted) else 0 end) prior_open,
SUM(case when c.report_date=&BIS_CURRENT_ASOF_DATE then b.leads-(b.leads_closed+b.leads_dead+b.leads_converted) else 0 end) curr_open,
SUM(case when c.report_date=&BIS_CURRENT_ASOF_DATE then b.leads else 0 end) curr_total,
0 leads_converted,
0 leads_new,
0 leads_dead,
0 leads_closed,
SUM(case when c.report_date=&BIS_CURRENT_ASOF_DATE then b.leads_changed else 0 end) curr_leads_changed
FROM FII_TIME_RPT_STRUCT c, '|| l_tables_b|| '
WHERE c.calendar_id=-1
AND c.report_date in (&BIS_CURRENT_ASOF_DATE,&BIS_CURRENT_EFFECTIVE_START_DATE - 1)
AND BITAND(c.record_type_id,1143)=c.record_type_id
'||l_where_b||'
GROUP BY '||l_col1_b||','||l_col2_b||','||l_col3_b||'
UNION ALL
/*Others for reps*/
SELECT '||l_hint||' '||l_col1_d||' BIM_SALES_GROUP,
'||l_col2_d||' VIEWBYID,
'||l_col3_d||' is_resource,
0 prior_open,
0 curr_open,
0 curr_total,
sum(b.leads_converted) leads_converted,
sum(b.leads_new) leads_new,
sum(b.leads_dead) leads_dead,
sum(b.leads_closed) leads_closed,
0 curr_leads_changed
FROM FII_TIME_RPT_STRUCT c, '|| l_tables_d|| '
WHERE c.calendar_id=-1
AND c.report_date = &BIS_CURRENT_ASOF_DATE
AND BITAND(c.record_type_id,:l_record_type)=c.record_type_id
AND ( leads_converted <> 0 or leads_new <> 0 or leads_dead <> 0 or leads_closed <> 0 )
'||l_where_d||'
GROUP BY'||l_col1_d||','||l_col2_d||','||l_col3_d ||'
) q ,JTF_RS_RESOURCE_EXTNS_VL a where q.resource_id=a.resource_id ';
l_query := 'SELECT BIM_SALES_GROUP VIEWBY,
VIEWBYID,
prior_open BIM_MEASURE1,
leads_new BIM_MEASURE2,
leads_converted BIM_MEASURE3,
leads_dead BIM_MEASURE4,
curr_open BIM_MEASURE5,
(curr_total-curr_leads_changed) BIM_MEASURE6,
leads_closed BIM_MEASURE8,
DECODE(curr_open,0,0,((curr_total-curr_leads_changed)/curr_open)*100) BIM_MEASURE7,
leads_converted BIM_MEASURE9,
DECODE('||''''||l_view_by||''''||', ''ORGANIZATION+JTF_ORG_SALES_GROUP'',DECODE(is_resource,1,NULL,'||''''||l_url_str||''''||' ) ,NULL) BIM_URL1,
NULL BIM_URL2,
decode(VIEWBYID,null,null,decode(leads_new,0,NULL,'||''''||l_url_str1||''''||'||'||''''||l_Metric_a||''''||'||'||''''||l_rpt_name||''''||'||VIEWBYID'||'||'||''''||l_context_info||')) BIM_URL3,
decode(VIEWBYID,null,null,decode(leads_converted,0,NULL,'||''''||l_url_str2||''''||'||'||''''||l_Metric_b||''''||'||'||''''||l_rpt_name||''''||'||VIEWBYID'||'||'||''''||l_context_info||')) BIM_URL4,
decode(VIEWBYID,null,null,decode(leads_closed,0,NULL,'||''''||l_url_str3||''''||'||'||''''||l_Metric_c||''''||'||'||''''||l_rpt_name||''''||'||VIEWBYID'||'||'||''''||l_context_info||')) BIM_URL5,
decode(VIEWBYID,null,null,decode(curr_open,0,NULL,'||''''||l_url_str4||''''||'||'||''''||l_Metric_d||''''||'||'||''''||l_rpt_name||''''||'||VIEWBYID'||'||'||''''||l_context_info||')) BIM_URL6,
decode(VIEWBYID,null,null,decode((curr_total-curr_leads_changed),0,NULL,'||''''||l_url_str5||''''||'||'||''''||l_Metric_e||''''||'||'||''''||l_rpt_name||''''||'||VIEWBYID'||'||'||''''||l_context_info||')) BIM_URL7,
SUM(prior_open) OVER() BIM_GRAND_TOTAL1,
SUM(leads_new) OVER() BIM_GRAND_TOTAL2,
SUM(leads_converted) OVER() BIM_GRAND_TOTAL3,
SUM(leads_dead) OVER() BIM_GRAND_TOTAL4,
SUM(curr_open) OVER() BIM_GRAND_TOTAL5,
SUM(curr_total-curr_leads_changed) OVER() BIM_GRAND_TOTAL6,
DECODE(SUM(curr_open) OVER(),0,0,(SUM(curr_total-curr_leads_changed) OVER()/SUM(curr_open) OVER())*100) BIM_GRAND_TOTAL7,
SUM(leads_closed) OVER() BIM_GRAND_TOTAL8,
SUM(leads_converted) OVER() BIM_GRAND_TOTAL9
FROM
(
select BIM_SALES_GROUP,
VIEWBYID,
is_resource,
sum(prior_open) prior_open,
sum(curr_open) curr_open,
sum(curr_total) curr_total,
sum(leads_converted) leads_converted,
sum(leads_new) leads_new,
sum(leads_dead) leads_dead,
sum(leads_closed) leads_closed,
sum(curr_leads_changed) curr_leads_changed
FROM
( ';
l_query :=l_query ||' SELECT d.group_name BIM_SALES_GROUP,VIEWBYID,is_resource,prior_open,curr_open,curr_total,
leads_converted,leads_new,leads_dead,leads_closed,curr_leads_changed from ( ';
l_query :=l_query ||' select '||l_hint||'
'||l_col1_a||' BIM_SALES_GROUP,
to_char( '||l_col2_a||' ) VIEWBYID,
'||l_col3_a||' is_resource,
SUM(case when c.report_date=&BIS_CURRENT_EFFECTIVE_START_DATE -1 and &BIS_CURRENT_EFFECTIVE_START_DATE<> :g_start_date then b.leads-(b.leads_closed+b.leads_dead+b.leads_converted) else 0 end) prior_open,
SUM(case when c.report_date=&BIS_CURRENT_ASOF_DATE then b.leads-(b.leads_closed+b.leads_dead+b.leads_converted) else 0 end) curr_open,
SUM(case when c.report_date=&BIS_CURRENT_ASOF_DATE then b.leads else 0 end) curr_total,
0 leads_converted,
0 leads_new,
0 leads_dead,
0 leads_closed,
SUM(case when c.report_date=&BIS_CURRENT_ASOF_DATE then b.leads_changed else 0 end) curr_leads_changed
FROM FII_TIME_RPT_STRUCT c,'|| l_tables_a|| '
WHERE c.calendar_id=-1
AND c.report_date in (&BIS_CURRENT_ASOF_DATE,&BIS_CURRENT_EFFECTIVE_START_DATE - 1)
AND BITAND(c.record_type_id,1143)=c.record_type_id
'||l_where_a||'
GROUP BY '||l_col1_a||','||l_col2_a||','||l_col3_a||'
UNION ALL
/*Others for sales group*/
select '||l_hint||'
'||l_col1_c||' BIM_SALES_GROUP,
to_char( '||l_col2_c||' ) VIEWBYID,
'||l_col3_c||' is_resource,
0 prior_open,
0 curr_open,
0 curr_total,
sum(leads_converted) leads_converted,
sum(leads_new) leads_new,
sum(leads_dead) leads_dead,
sum(leads_closed) leads_closed,
0 curr_leads_changed
FROM FII_TIME_RPT_STRUCT c,'|| l_tables_c|| '
WHERE c.calendar_id=-1
AND c.report_date = &BIS_CURRENT_ASOF_DATE
AND BITAND(c.record_type_id,:l_record_type)=c.record_type_id
AND ( leads_converted <> 0 or leads_new <> 0 or leads_dead <> 0 or leads_closed <> 0 )
'||l_where_c||'
GROUP BY '||l_col1_c||','||l_col2_c||','||l_col3_c;
l_query := 'SELECT BIM_SALES_GROUP VIEWBY,
VIEWBYID,
prior_open BIM_MEASURE1,
leads_new BIM_MEASURE2,
leads_converted BIM_MEASURE3,
leads_dead BIM_MEASURE4,
curr_open BIM_MEASURE5,
(curr_total-curr_leads_changed) BIM_MEASURE6,
leads_closed BIM_MEASURE8,
leads_converted BIM_MEASURE9,
DECODE('||''''||l_view_by||''''||', ''ORGANIZATION+JTF_ORG_SALES_GROUP'',DECODE(is_resource,1,NULL,'||''''||l_url_str||''''||' ) ,NULL) BIM_URL1,
NULL BIM_URL2,
decode(VIEWBYID,null,null,decode(leads_new,0,NULL,'||''''||l_url_str1||''''||'||'||''''||l_Metric_a||''''||'||'||''''||l_rpt_name||''''||'||VIEWBYID'||'||'||''''||l_context_info||')) BIM_URL3,
decode(VIEWBYID,null,null,decode(leads_converted,0,NULL,'||''''||l_url_str2||''''||'||'||''''||l_Metric_b||''''||'||'||''''||l_rpt_name||''''||'||VIEWBYID'||'||'||''''||l_context_info||')) BIM_URL4,
decode(VIEWBYID,null,null,decode(leads_closed,0,NULL,'||''''||l_url_str3||''''||'||'||''''||l_Metric_c||''''||'||'||''''||l_rpt_name||''''||'||VIEWBYID'||'||'||''''||l_context_info||')) BIM_URL5,
decode(VIEWBYID,null,null,decode(curr_open,0,NULL,'||''''||l_url_str4||''''||'||'||''''||l_Metric_d||''''||'||'||''''||l_rpt_name||''''||'||VIEWBYID'||'||'||''''||l_context_info||')) BIM_URL6,
decode(VIEWBYID,null,null,decode((curr_total-curr_leads_changed),0,NULL,'||''''||l_url_str5||''''||'||'||''''||l_Metric_e||''''||'||'||''''||l_rpt_name||''''||'||VIEWBYID'||'||'||''''||l_context_info||')) BIM_URL7,
DECODE(curr_open,0,0,((curr_total-curr_leads_changed)/curr_open)*100) BIM_MEASURE7,
SUM(prior_open) OVER() BIM_GRAND_TOTAL1,
SUM(leads_new) OVER() BIM_GRAND_TOTAL2,
SUM(leads_converted) OVER() BIM_GRAND_TOTAL3,
SUM(leads_dead) OVER() BIM_GRAND_TOTAL4,
SUM(curr_open) OVER() BIM_GRAND_TOTAL5,
SUM(curr_total-curr_leads_changed) OVER() BIM_GRAND_TOTAL6,
DECODE(SUM(curr_open) OVER(),0,0,(SUM(curr_total-curr_leads_changed) OVER()/SUM(curr_open) OVER())*100) BIM_GRAND_TOTAL7,
SUM(leads_closed) OVER() BIM_GRAND_TOTAL8,
SUM(leads_converted) OVER() BIM_GRAND_TOTAL9
FROM
(
select ';
SELECT '||l_hint||' '||l_col1_b||' BIM_SALES_GROUP,
to_char( '||l_col2_b||' ) VIEWBYID,
'||l_col3_b||' is_resource,
b.resource_id resource_id,
SUM(case when c.report_date=&BIS_CURRENT_EFFECTIVE_START_DATE - 1 and &BIS_CURRENT_EFFECTIVE_START_DATE<> :g_start_date then b.leads-(b.leads_closed+b.leads_dead+b.leads_converted) else 0 end) prior_open,
SUM(case when c.report_date=&BIS_CURRENT_ASOF_DATE then b.leads-(b.leads_closed+b.leads_dead+b.leads_converted) else 0 end) curr_open,
SUM(case when c.report_date=&BIS_CURRENT_ASOF_DATE then b.leads else 0 end) curr_total,
0 leads_converted,
0 leads_new,
0 leads_dead,
0 leads_closed,
SUM(case when c.report_date=&BIS_CURRENT_ASOF_DATE then b.leads_changed else 0 end) curr_leads_changed
FROM FII_TIME_RPT_STRUCT c, '|| l_tables_b|| '
WHERE c.calendar_id=-1
AND c.report_date in (&BIS_CURRENT_ASOF_DATE,&BIS_CURRENT_EFFECTIVE_START_DATE - 1)
AND BITAND(c.record_type_id,1143)=c.record_type_id
'||l_where_b||'
GROUP BY '||l_col1_b||','||l_col2_b||','||l_col3_b||' ,b.resource_id
UNION ALL
/*Others for reps*/
SELECT '||l_hint||' '||l_col1_d||' BIM_SALES_GROUP,
to_char( '||l_col2_d||' ) VIEWBYID,
'||l_col3_d||' is_resource,
b.resource_id resource_id,
0 prior_open,
0 curr_open,
0 curr_total,
sum(b.leads_converted) leads_converted,
sum(b.leads_new) leads_new,
sum(b.leads_dead) leads_dead,
sum(b.leads_closed) leads_closed,
0 curr_leads_changed
FROM FII_TIME_RPT_STRUCT c, '|| l_tables_d|| '
WHERE c.calendar_id=-1
AND c.report_date = &BIS_CURRENT_ASOF_DATE
AND BITAND(c.record_type_id,:l_record_type)=c.record_type_id
AND ( leads_converted <> 0 or leads_new <> 0 or leads_dead <> 0 or leads_closed <> 0 )
'||l_where_d||'
GROUP BY'||l_col1_d||','||l_col2_d||','||l_col3_d||',b.resource_id
) q,JTF_RS_RESOURCE_EXTNS_VL a where
q.resource_id=a.resource_id
GROUP BY ';
l_query := 'SELECT
NULL VIEWBY,
NULL VIEWBYID,
NULL BIM_MEASURE1,
NULL BIM_MEASURE2,
NULL BIM_MEASURE3,
NULL BIM_MEASURE4,
NULL BIM_MEASURE5,
NULL BIM_MEASURE6,
NULL BIM_MEASURE8,
NULL BIM_MEASURE7,
NULL BIM_MEASURE9,
NULL BIM_URL1,
NULL BIM_URL2,
NULL BIM_URL3,
NULL BIM_URL4,
NULL BIM_URL5,
NULL BIM_URL6,
NULL BIM_URL7,
NULL BIM_GRAND_TOTAL1,
NULL BIM_GRAND_TOTAL2,
NULL BIM_GRAND_TOTAL3,
NULL BIM_GRAND_TOTAL4,
NULL BIM_GRAND_TOTAL5,
NULL BIM_GRAND_TOTAL6,
NULL bim_GRAND_TOTAL7,
NULL bim_GRAND_TOTAL8,
NULL bim_GRAND_TOTAL9
FROM dual ';
AND b.update_time_id= -1
AND b.update_period_type_id= -1
AND b.resource_id = :l_resource_id ';
AND b.update_time_id=c.time_id
AND b.update_period_type_id=c.period_type_id
and b.time_id = :l_time_id
and b.period_type_id = :l_period_type_id
AND b.resource_id = :l_resource_id ';
AND b.update_time_id= -1
AND b.update_period_type_id= -1
AND b.resource_id <> :l_resource_id ';
AND b.update_time_id=c.time_id
AND b.update_period_type_id=c.period_type_id
and b.time_id = :l_time_id
and b.period_type_id = :l_period_type_id
AND b.resource_id <> :l_resource_id ';
AND b.update_time_id= -1
AND b.update_period_type_id= -1
AND b.resource_id = :l_resource_id ';
AND b.update_time_id= -1
AND b.update_period_type_id= -1
AND b.resource_id <> :l_resource_id ';
AND b.update_time_id= -1
AND b.update_period_type_id= -1
AND b.resource_id = :l_resource_id ';
AND b.update_time_id=c.time_id
AND b.update_period_type_id=c.period_type_id
and b.time_id = :l_time_id
and b.period_type_id = :l_period_type_id
AND b.resource_id = :l_resource_id ' ;
AND b.update_time_id= -1
AND b.update_period_type_id= -1
AND b.resource_id = :l_resource_id ';
AND b.update_period_type_id = -1
AND b.update_time_id = -1
AND b.resource_id = :l_resource_id
AND b.product_category_id = edh.child_id AND edh.object_type = ''CATEGORY_SET'' AND edh.object_id = mtl.category_set_id AND mtl.functional_area_id = 11 AND edh.dbi_flag = ''Y'' AND edh.parent_id = &ITEM+ENI_ITEM_VBH_CAT ';
AND b.update_time_id=c.time_id
AND b.update_period_type_id=c.period_type_id
and b.time_id = :l_time_id
and b.period_type_id = :l_period_type_id
AND b.resource_id = :l_resource_id
AND b.product_category_id = edh.child_id AND edh.object_type = ''CATEGORY_SET'' AND edh.object_id = mtl.category_set_id AND mtl.functional_area_id = 11 AND edh.dbi_flag = ''Y'' AND edh.parent_id = &ITEM+ENI_ITEM_VBH_CAT ';
AND b.update_period_type_id = -1
AND b.update_time_id = -1
AND b.resource_id <> :l_resource_id ';
AND b.update_time_id=c.time_id
AND b.update_period_type_id=c.period_type_id
and b.time_id = :l_time_id
and b.period_type_id = :l_period_type_id
AND b.resource_id <> :l_resource_id ';
AND b.update_period_type_id = -1
AND b.update_time_id = -1
AND b.resource_id = :l_resource_id
AND b.product_category_id = edh.child_id AND edh.object_type = ''CATEGORY_SET'' AND edh.object_id = mtl.category_set_id AND mtl.functional_area_id = 11 AND edh.dbi_flag = ''Y'' AND edh.parent_id = &ITEM+ENI_ITEM_VBH_CAT ';
AND b.update_period_type_id = -1
AND b.update_time_id = -1
AND b.resource_id <> :l_resource_id
AND b.product_category_id = edh.child_id AND edh.object_type = ''CATEGORY_SET'' AND edh.object_id = mtl.category_set_id AND mtl.functional_area_id = 11 AND edh.dbi_flag = ''Y'' AND edh.parent_id = &ITEM+ENI_ITEM_VBH_CAT ';
AND b.update_period_type_id = -1
AND b.update_time_id = -1
AND b.resource_id = :l_resource_id ' ;
AND b.update_time_id=c.time_id
AND b.update_period_type_id=c.period_type_id
and b.time_id = :l_time_id
and b.period_type_id = :l_period_type_id
AND b.resource_id = :l_resource_id ' ;
AND b.update_period_type_id = -1
AND b.update_time_id = -1
AND b.resource_id = :l_resource_id
AND b.product_category_id = edh.child_id AND edh.object_type = ''CATEGORY_SET'' AND edh.object_id = mtl.category_set_id AND mtl.functional_area_id = 11 AND edh.dbi_flag = ''Y'' AND edh.parent_id = &ITEM+ENI_ITEM_VBH_CAT ';
/* If Only group is selected and rep is not selected */
IF (l_resource_id is null) THEN
l_query :=
'SELECT BIM_SALES_GROUP VIEWBY,
VIEWBYID,
oppt_amt BIM_ATTRIBUTE1,
decode(prev_oppt_amt,0,NULL,((oppt_amt - prev_oppt_amt)/prev_oppt_amt)*100) BIM_ATTRIBUTE2,
leads_converted BIM_ATTRIBUTE3,
DECODE(leads_converted,0,NULL,conversion_time/leads_converted) BIM_ATTRIBUTE4,
DECODE((prev_open+leads_new),0,NULL,(leads_converted/(prev_open+leads_new))*100) BIM_ATTRIBUTE5,
DECODE(prev_lead_converted,0,NULL,((leads_converted - prev_lead_converted)/prev_lead_converted)*100) BIM_ATTRIBUTE6,
NULL BIM_ATTRIBUTE13,
DECODE(leaf_node_flag,''Y'',NULL,'||''''||l_url_str||''''||' ) BIM_ATTRIBUTE15,
oppt_amt BIM_ATTRIBUTE16,
DECODE((prev_open+leads_new),0,NULL,(leads_converted/(prev_open+leads_new))*100) BIM_ATTRIBUTE17,
SUM(oppt_amt) OVER() BIM_GRAND_TOTAL1,
DECODE(sum(prev_oppt_amt) over(),0,NULL,(sum(oppt_amt - prev_oppt_amt) over()/sum(prev_oppt_amt) over())*100) BIM_GRAND_TOTAL2,
SUM(leads_converted) OVER() BIM_GRAND_TOTAL3,
DECODE(sum(leads_converted) over(),0,NULL,sum(conversion_time) over()/sum(leads_converted) over()) BIM_GRAND_TOTAL4,
DECODE(sum(open_new) over(),0,NULL,(sum(leads_converted) over()/sum(open_new) over())*100) BIM_GRAND_TOTAL5
FROM (
SELECT
BIM_SALES_GROUP,
VIEWBYID,
leaf_node_flag,
sum(oppt_amt) oppt_amt,
sum(prev_oppt_amt) prev_oppt_amt,
sum(leads_new) leads_new,
sum(leads_converted) leads_converted,
sum(prev_open+leads_new) open_new,
sum(conversion_time) conversion_time,
sum(prev_open) prev_open,
sum(prev_lead_converted) prev_lead_converted
FROM
(
SELECT /*+ leading(c) */
p.value BIM_SALES_GROUP,
p.parent_id VIEWBYID,
p.leaf_node_flag leaf_node_flag,
0 oppt_amt,
0 prev_oppt_amt,
sum(decode(c.report_date,&BIS_CURRENT_ASOF_DATE,leads_new,0)) leads_new,
sum(decode(c.report_date,&BIS_CURRENT_ASOF_DATE,leads_converted,0)) leads_converted,
sum(decode(c.report_date,&BIS_CURRENT_ASOF_DATE,conversion_time,0)) conversion_time,
0 prev_open,
sum(decode(c.report_date,&BIS_PREVIOUS_ASOF_DATE,leads_converted,0)) prev_lead_converted
FROM FII_TIME_RPT_STRUCT c, BIM_I_LP_GEN_SG_MV b
,( SELECT e.parent_id parent_id ,e.value value,e.leaf_node_flag leaf_node_flag
FROM eni_item_vbh_nodes_v e
WHERE e.top_node_flag=''Y''
AND e.child_id = e.parent_id) p
,eni_denorm_hierarchies edh
,mtl_default_category_sets d
WHERE b.group_id = &ORGANIZATION+JTF_ORG_SALES_GROUP
AND b.product_category_id = edh.child_id
AND edh.object_type = ''CATEGORY_SET''
AND edh.object_id = d.category_set_id
AND d.functional_area_id = 11
AND edh.dbi_flag = ''Y''
AND edh.parent_id = p.parent_id
AND c.calendar_id=-1
AND c.report_date in (&BIS_CURRENT_ASOF_DATE,&BIS_PREVIOUS_ASOF_DATE)
AND BITAND(c.record_type_id,:l_record_type)=c.record_type_id
AND b.time_id=c.time_id
AND b.period_type_id=c.period_type_id
AND b.update_period_type_id = -1
AND b.update_time_id = -1
AND b.resource_id =:l_resource_id
GROUP BY p.value,p.parent_id,p.leaf_node_flag
UNION ALL
select /*+ leading(c) */
p.value BIM_SALES_GROUP,
p.parent_id VIEWBYID,
p.leaf_node_flag leaf_node_flag,
0 oppt_amt,
0 prev_oppt_amt,
0 leads_new,
0 leads_converted,
0 conversion_time,
sum(b.leads-(b.leads_closed+b.leads_dead+b.leads_converted)) prev_open,
0 prev_lead_converted
FROM FII_TIME_RPT_STRUCT c, BIM_I_LP_GEN_SG_MV b
,( SELECT e.parent_id parent_id ,e.value value,e.leaf_node_flag leaf_node_flag
FROM eni_item_vbh_nodes_v e
WHERE e.top_node_flag=''Y''
AND e.child_id = e.parent_id) p
,eni_denorm_hierarchies edh
,mtl_default_category_sets d
WHERE b.group_id = &ORGANIZATION+JTF_ORG_SALES_GROUP
AND b.product_category_id = edh.child_id
AND edh.object_type = ''CATEGORY_SET''
AND edh.object_id = d.category_set_id
AND d.functional_area_id = 11
AND edh.dbi_flag = ''Y''
AND edh.parent_id = p.parent_id
AND c.calendar_id=-1
AND c.report_date = &BIS_CURRENT_EFFECTIVE_START_DATE - 1
AND BITAND(c.record_type_id,1143)=c.record_type_id
AND b.time_id=c.time_id
AND b.period_type_id=c.period_type_id
AND b.update_period_type_id = -1
AND b.update_time_id = -1
AND b.resource_id =:l_resource_id
GROUP BY p.value,p.parent_id,p.leaf_node_flag
HAVING sum(b.leads-(b.leads_closed+b.leads_dead+b.leads_converted)) <> 0
UNION ALL/* For Opportunities from Sales MVs*/
SELECT /*+ leading(c) */ p.value BIM_SALES_GROUP,p.parent_id VIEWBYID,p.leaf_node_flag leaf_node_flag,
sum(decode(c.report_date,&BIS_CURRENT_ASOF_DATE,cnv_opty_amt'||l_curr_suffix||',0)) oppt_amt,
sum(decode(c.report_date,&BIS_PREVIOUS_ASOF_DATE,cnv_opty_amt'||l_curr_suffix||',0)) prev_oppt_amt,
0,0,0,0,0
FROM FII_TIME_RPT_STRUCT c, bil_bi_opty_pg_mv f
,( SELECT e.parent_id parent_id ,e.value value,e.leaf_node_flag leaf_node_flag
FROM eni_item_vbh_nodes_v e
WHERE e.top_node_flag=''Y''
AND e.child_id = e.parent_id) p
,eni_denorm_hierarchies edh
,mtl_default_category_sets d
WHERE f.effective_time_id=c.time_id
AND f.parent_sales_group_id = &ORGANIZATION+JTF_ORG_SALES_GROUP
AND f.effective_period_type_id=c.period_type_id
--AND f.salesrep_id is null
AND f.product_category_id = edh.child_id
AND edh.object_type = ''CATEGORY_SET''
AND edh.object_id = d.category_set_id
AND d.functional_area_id = 11
AND edh.dbi_flag = ''Y''
AND edh.parent_id = p.parent_id
AND c.calendar_id=-1
AND c.report_date in (&BIS_CURRENT_ASOF_DATE,&BIS_PREVIOUS_ASOF_DATE)
AND BITAND(c.record_type_id,:l_record_type)=c.record_type_id
GROUP BY p.value,p.parent_id,p.leaf_node_flag
)
GROUP BY BIM_SALES_GROUP,VIEWBYID,leaf_node_flag
HAVING
sum(leads_converted) > 0
OR sum(leads_new) > 0
OR sum(prev_open)> 0
OR sum(oppt_amt) > 0
OR sum(prev_oppt_amt) > 0
OR sum(conversion_time) > 0
OR sum(prev_lead_converted) > 0
)';
/* If Only rep is selected */
l_query := 'SELECT BIM_SALES_GROUP VIEWBY,
VIEWBYID,
oppt_amt BIM_ATTRIBUTE1,
decode(prev_oppt_amt,0,NULL,((oppt_amt - prev_oppt_amt)/prev_oppt_amt)*100) BIM_ATTRIBUTE2,
leads_converted BIM_ATTRIBUTE3,
DECODE(leads_converted,0,NULL,conversion_time/leads_converted) BIM_ATTRIBUTE4,
DECODE((prev_open+leads_new),0,NULL,(leads_converted/(prev_open+leads_new))*100) BIM_ATTRIBUTE5,
DECODE(prev_lead_converted,0,NULL,((leads_converted - prev_lead_converted)/prev_lead_converted)*100) BIM_ATTRIBUTE6,
NULL BIM_ATTRIBUTE13,
DECODE(leaf_node_flag,''Y'',NULL,'||''''||l_url_str||''''||' ) BIM_ATTRIBUTE15,
oppt_amt BIM_ATTRIBUTE16,
DECODE((prev_open+leads_new),0,NULL,(leads_converted/(prev_open+leads_new))*100) BIM_ATTRIBUTE17,
SUM(oppt_amt) OVER() BIM_GRAND_TOTAL1,
DECODE(sum(prev_oppt_amt) over(),0,NULL,(sum(oppt_amt - prev_oppt_amt) over()/sum(prev_oppt_amt) over())*100) BIM_GRAND_TOTAL2,
SUM(leads_converted) OVER() BIM_GRAND_TOTAL3,
DECODE(sum(leads_converted) over(),0,NULL,sum(conversion_time) over()/sum(leads_converted) over()) BIM_GRAND_TOTAL4,
DECODE(sum(open_new) over(),0,NULL,(sum(leads_converted) over()/sum(open_new) over())*100) BIM_GRAND_TOTAL5
FROM (
SELECT
BIM_SALES_GROUP,
VIEWBYID,
leaf_node_flag,
sum(oppt_amt) oppt_amt,
sum(prev_oppt_amt) prev_oppt_amt,
sum(leads_new) leads_new,
sum(leads_converted) leads_converted,
sum(prev_open+leads_new) open_new,
sum(conversion_time) conversion_time,
sum(prev_open) prev_open,
sum(prev_lead_converted) prev_lead_converted
FROM
(
SELECT /*+ leading(c) */
p.value BIM_SALES_GROUP,
p.parent_id VIEWBYID,
p.leaf_node_flag leaf_node_flag,
0 oppt_amt,
0 prev_oppt_amt,
sum(decode(c.report_date,&BIS_CURRENT_ASOF_DATE,leads_new,0)) leads_new,
sum(decode(c.report_date,&BIS_CURRENT_ASOF_DATE,leads_converted,0)) leads_converted,
sum(decode(c.report_date,&BIS_CURRENT_ASOF_DATE,conversion_time,0)) conversion_time,
0 prev_open,
sum(decode(c.report_date,&BIS_PREVIOUS_ASOF_DATE,leads_converted,0)) prev_lead_converted
FROM FII_TIME_RPT_STRUCT c, BIM_I_LP_GEN_SG_MV b
,( SELECT e.parent_id parent_id ,e.value value,e.leaf_node_flag leaf_node_flag
FROM eni_item_vbh_nodes_v e
WHERE e.top_node_flag=''Y''
AND e.child_id = e.parent_id) p
,eni_denorm_hierarchies edh
,mtl_default_category_sets d
WHERE b.group_id = :l_group_id
AND b.product_category_id = edh.child_id
AND edh.object_type = ''CATEGORY_SET''
AND edh.object_id = d.category_set_id
AND d.functional_area_id = 11
AND edh.dbi_flag = ''Y''
AND edh.parent_id = p.parent_id
AND c.calendar_id=-1
AND c.report_date in (&BIS_CURRENT_ASOF_DATE,&BIS_PREVIOUS_ASOF_DATE)
AND BITAND(c.record_type_id,:l_record_type)=c.record_type_id
AND b.time_id=c.time_id
AND b.period_type_id=c.period_type_id
AND b.update_period_type_id = -1
AND b.update_time_id = -1
AND b.resource_id = :l_resource_id
GROUP BY p.value,p.parent_id,p.leaf_node_flag
UNION ALL
select /*+ leading(c) */
p.value BIM_SALES_GROUP,
p.parent_id VIEWBYID,
p.leaf_node_flag leaf_node_flag,
0 oppt_amt,
0 prev_oppt_amt,
0 leads_new,
0 leads_converted,
0 conversion_time,
sum(b.leads-(b.leads_closed+b.leads_dead+b.leads_converted)) prev_open,
0 prev_lead_converted
FROM FII_TIME_RPT_STRUCT c,BIM_I_LP_GEN_SG_MV b
,( SELECT e.parent_id parent_id ,e.value value,e.leaf_node_flag leaf_node_flag
FROM eni_item_vbh_nodes_v e
WHERE e.top_node_flag=''Y''
AND e.child_id = e.parent_id) p
,eni_denorm_hierarchies edh
,mtl_default_category_sets d
WHERE b.group_id = :l_group_id
AND b.product_category_id = edh.child_id
AND edh.object_type = ''CATEGORY_SET''
AND edh.object_id = d.category_set_id
AND d.functional_area_id = 11
AND edh.dbi_flag = ''Y''
AND edh.parent_id = p.parent_id
AND c.calendar_id=-1
AND c.report_date = &BIS_CURRENT_EFFECTIVE_START_DATE - 1
AND BITAND(c.record_type_id,1143)=c.record_type_id
AND b.time_id=c.time_id
AND b.period_type_id=c.period_type_id
AND b.update_period_type_id = -1
AND b.update_time_id = -1
AND b.resource_id = :l_resource_id
GROUP BY p.value,p.parent_id,p.leaf_node_flag
HAVING sum(b.leads-(b.leads_closed+b.leads_dead+b.leads_converted)) <> 0
UNION ALL /* For Oppt from Sales MV*/
SELECT /*+ leading(c) */
p.value BIM_SALES_GROUP,
p.parent_id VIEWBYID,
p.leaf_node_flag leaf_node_flag,
sum(decode(c.report_date,&BIS_CURRENT_ASOF_DATE,cnv_opty_amt'||l_curr_suffix||',0)) oppt_amt,
sum(decode(c.report_date,&BIS_PREVIOUS_ASOF_DATE,cnv_opty_amt'||l_curr_suffix||',0)) prev_oppt_amt,
0,0,0,0,0
FROM FII_TIME_RPT_STRUCT c, bil_bi_opty_pg_mv f
, ( SELECT e.parent_id parent_id ,e.value value,e.leaf_node_flag leaf_node_flag
FROM eni_item_vbh_nodes_v e
WHERE e.top_node_flag=''Y''
AND e.child_id = e.parent_id) p
,eni_denorm_hierarchies edh
,mtl_default_category_sets d
WHERE f.effective_time_id=c.time_id
AND f.parent_sales_group_id = :l_group_id
AND f.effective_period_type_id=c.period_type_id
AND f.salesrep_id = :l_resource_id
AND f.product_category_id=edh.child_id
AND edh.object_type = ''CATEGORY_SET''
AND edh.object_id = d.category_set_id
AND d.functional_area_id = 11
AND edh.dbi_flag = ''Y''
AND edh.parent_id = p.parent_id
AND c.calendar_id=-1
AND c.report_date in (&BIS_CURRENT_ASOF_DATE,&BIS_PREVIOUS_ASOF_DATE)
AND BITAND(c.record_type_id,:l_record_type)=c.record_type_id
GROUP BY p.value,p.parent_id,p.leaf_node_flag
)
GROUP BY BIM_SALES_GROUP,VIEWBYID,leaf_node_flag
HAVING
sum(leads_converted) > 0
OR sum(leads_new) > 0
OR sum(prev_open)> 0
OR sum(oppt_amt) > 0
OR sum(prev_oppt_amt) > 0
OR sum(conversion_time) > 0
OR sum(prev_lead_converted) > 0
)';
/* If Only group is selected and rep is not selected */
IF (l_resource_id is null) THEN
l_query := 'SELECT BIM_SALES_GROUP VIEWBY,
VIEWBYID,
oppt_amt BIM_ATTRIBUTE1,
decode(prev_oppt_amt,0,NULL,((oppt_amt - prev_oppt_amt)/prev_oppt_amt)*100) BIM_ATTRIBUTE2,
leads_converted BIM_ATTRIBUTE3,
DECODE(leads_converted,0,NULL,conversion_time/leads_converted) BIM_ATTRIBUTE4,
DECODE((prev_open+leads_new),0,NULL,(leads_converted/(prev_open+leads_new))*100) BIM_ATTRIBUTE5,
DECODE(prev_lead_converted,0,NULL,((leads_converted - prev_lead_converted)/prev_lead_converted)*100) BIM_ATTRIBUTE6,
NULL BIM_ATTRIBUTE13,
DECODE(leaf_node_flag,''Y'',NULL,'||''''||l_url_str||''''||' ) BIM_ATTRIBUTE15,
oppt_amt BIM_ATTRIBUTE16,
DECODE((prev_open+leads_new),0,NULL,(leads_converted/(prev_open+leads_new))*100) BIM_ATTRIBUTE17,
SUM(oppt_amt) OVER() BIM_GRAND_TOTAL1,
DECODE(sum(prev_oppt_amt) over(),0,NULL,(sum(oppt_amt - prev_oppt_amt) over()/sum(prev_oppt_amt) over())*100) BIM_GRAND_TOTAL2,
SUM(leads_converted) OVER() BIM_GRAND_TOTAL3,
DECODE(sum(leads_converted) over(),0,NULL,sum(conversion_time) over()/sum(leads_converted) over()) BIM_GRAND_TOTAL4,
DECODE(sum(open_new) over(),0,NULL,(sum(leads_converted) over()/sum(open_new) over())*100) BIM_GRAND_TOTAL5
FROM (
SELECT
BIM_SALES_GROUP,
VIEWBYID,
leaf_node_flag,
sum(oppt_amt) oppt_amt,
sum(prev_oppt_amt) prev_oppt_amt,
sum(leads_new) leads_new,
sum(leads_converted) leads_converted,
sum(prev_open+leads_new) open_new,
sum(conversion_time) conversion_time,
sum(prev_open) prev_open,
sum(prev_lead_converted) prev_lead_converted
FROM
(
/*********children of the selected category*********/
SELECT /*+ leading(c) */
p.value BIM_SALES_GROUP,
p.id VIEWBYID,
p.leaf_node_flag leaf_node_flag,
0 oppt_amt,
0 prev_oppt_amt,
sum(decode(c.report_date,&BIS_CURRENT_ASOF_DATE,leads_new,0)) leads_new,
sum(decode(c.report_date,&BIS_CURRENT_ASOF_DATE,leads_converted,0)) leads_converted,
sum(decode(c.report_date,&BIS_CURRENT_ASOF_DATE,conversion_time,0)) conversion_time,
0 prev_open,
sum(decode(c.report_date,&BIS_PREVIOUS_ASOF_DATE,leads_converted,0)) prev_lead_converted
FROM FII_TIME_RPT_STRUCT c, BIM_I_LP_GEN_SG_MV b
,eni_denorm_hierarchies edh
,mtl_default_category_sets mdc
,(SELECT e.id,e.value,leaf_node_flag
FROM eni_item_vbh_nodes_v e
WHERE e.parent_id =&ITEM+ENI_ITEM_VBH_CAT
AND e.id = e.child_id
AND ((e.leaf_node_flag=''N'' AND e.parent_id<>e.id) OR e.leaf_node_flag=''Y'')
) p
WHERE b.group_id = &ORGANIZATION+JTF_ORG_SALES_GROUP
AND b.product_category_id = edh.child_id
AND edh.object_type = ''CATEGORY_SET''
AND edh.object_id = mdc.category_set_id
AND mdc.functional_area_id = 11
AND edh.dbi_flag = ''Y''
AND edh.parent_id = p.id
AND c.calendar_id=-1
AND c.report_date in (&BIS_CURRENT_ASOF_DATE,&BIS_PREVIOUS_ASOF_DATE)
AND BITAND(c.record_type_id,:l_record_type)=c.record_type_id
AND b.time_id=c.time_id
AND b.period_type_id=c.period_type_id
AND b.update_period_type_id = -1
AND b.update_time_id = -1
AND b.resource_id = :l_resource_id
GROUP BY p.value,p.id,p.leaf_node_flag
UNION ALL
select /*+ leading(c) */
p.value BIM_SALES_GROUP,
p.id VIEWBYID,
p.leaf_node_flag leaf_node_flag,
0 oppt_amt,
0 prev_oppt_amt,
0 leads_new,
0 leads_converted,
0 conversion_time,
sum(b.leads-(b.leads_closed+b.leads_dead+b.leads_converted)) prev_open,
0 prev_lead_converted
FROM FII_TIME_RPT_STRUCT c, BIM_I_LP_GEN_SG_MV b
,eni_denorm_hierarchies edh
,mtl_default_category_sets mdc
,(SELECT e.id,e.value,leaf_node_flag
FROM eni_item_vbh_nodes_v e
WHERE e.parent_id =&ITEM+ENI_ITEM_VBH_CAT
AND e.id = e.child_id
AND ((e.leaf_node_flag=''N'' AND e.parent_id<>e.id) OR e.leaf_node_flag=''Y'')
) p
WHERE b.group_id = &ORGANIZATION+JTF_ORG_SALES_GROUP
AND b.product_category_id = edh.child_id
AND edh.object_type = ''CATEGORY_SET''
AND edh.object_id = mdc.category_set_id
AND mdc.functional_area_id = 11
AND edh.dbi_flag = ''Y''
AND edh.parent_id = p.id
AND c.calendar_id=-1
AND c.report_date = &BIS_CURRENT_EFFECTIVE_START_DATE - 1
AND BITAND(c.record_type_id,1143)=c.record_type_id
AND b.time_id=c.time_id
AND b.period_type_id=c.period_type_id
AND b.update_period_type_id = -1
AND b.update_time_id = -1
AND b.resource_id = :l_resource_id
GROUP BY p.value,p.id,p.leaf_node_flag
HAVING sum(b.leads-(b.leads_closed+b.leads_dead+b.leads_converted)) <> 0
UNION ALL
/******Directly Assigned to Category*******/
SELECT /*+ leading(c) */
bim_pmv_dbi_utl_pkg.get_lookup_value('||''''||'DASS'||''''||')'||' BIM_SALES_GROUP,
p.id VIEWBYID,
''Y'' leaf_node_flag,
0 oppt_amt,
0 prev_oppt_amt,
sum(decode(c.report_date,&BIS_CURRENT_ASOF_DATE,leads_new,0)) leads_new,
sum(decode(c.report_date,&BIS_CURRENT_ASOF_DATE,leads_converted,0)) leads_converted,
sum(decode(c.report_date,&BIS_CURRENT_ASOF_DATE,conversion_time,0)) conversion_time,
0 prev_open,
sum(decode(c.report_date,&BIS_PREVIOUS_ASOF_DATE,leads_converted,0)) prev_lead_converted
FROM FII_TIME_RPT_STRUCT c, BIM_I_LP_GEN_SG_MV b
,(SELECT e.id id,e.value value
FROM eni_item_vbh_nodes_v e
WHERE e.parent_id = &ITEM+ENI_ITEM_VBH_CAT
AND e.parent_id = e.child_id
AND leaf_node_flag <> ''Y''
) p
WHERE b.group_id = &ORGANIZATION+JTF_ORG_SALES_GROUP
AND p.id = b.product_category_id
AND c.calendar_id=-1
AND c.report_date in (&BIS_CURRENT_ASOF_DATE,&BIS_PREVIOUS_ASOF_DATE)
AND BITAND(c.record_type_id,:l_record_type)=c.record_type_id
AND b.time_id=c.time_id
AND b.period_type_id=c.period_type_id
AND b.update_period_type_id = -1
AND b.update_time_id = -1
AND b.resource_id =:l_resource_id
AND b.item_id = ''-1''
GROUP BY p.value,p.id
UNION ALL
select /*+ leading(c) */
bim_pmv_dbi_utl_pkg.get_lookup_value('||''''||'DASS'||''''||')'||' BIM_SALES_GROUP,
p.id VIEWBYID,
''Y'' leaf_node_flag,
0 oppt_amt,
0 prev_oppt_amt,
0 leads_new,
0 leads_converted,
0 conversion_time,
sum(b.leads-(b.leads_closed+b.leads_dead+b.leads_converted)) prev_open,
0 prev_lead_converted
FROM FII_TIME_RPT_STRUCT c, BIM_I_LP_GEN_SG_MV b
,(SELECT e.id id,e.value value
FROM eni_item_vbh_nodes_v e
WHERE e.parent_id = &ITEM+ENI_ITEM_VBH_CAT
AND e.parent_id = e.child_id
AND leaf_node_flag <> ''Y''
) p
WHERE b.group_id = &ORGANIZATION+JTF_ORG_SALES_GROUP
AND p.id = b.product_category_id
AND c.calendar_id=-1
AND c.report_date = &BIS_CURRENT_EFFECTIVE_START_DATE - 1
AND BITAND(c.record_type_id,1143)=c.record_type_id
AND b.time_id=c.time_id
AND b.period_type_id=c.period_type_id
AND b.update_period_type_id = -1
AND b.update_time_id = -1
AND b.resource_id =:l_resource_id
AND b.item_id = ''-1''
GROUP BY p.value,p.id
HAVING sum(b.leads-(b.leads_closed+b.leads_dead+b.leads_converted)) <> 0
UNION ALL /* For Oppt from Sales MV*/
SELECT /*+ leading(c) */
p.value BIM_SALES_GROUP,
p.id VIEWBYID,
p.leaf_node_flag leaf_node_flag,
sum(decode(c.report_date,&BIS_CURRENT_ASOF_DATE,cnv_opty_amt'||l_curr_suffix||',0)) oppt_amt,
sum(decode(c.report_date,&BIS_PREVIOUS_ASOF_DATE,cnv_opty_amt'||l_curr_suffix||',0)) prev_oppt_amt,
0,0,0,0,0
FROM FII_TIME_RPT_STRUCT c, bil_bi_opty_pg_mv f
,eni_denorm_hierarchies edh
,mtl_default_category_sets mdc
,(SELECT e.id,e.value,leaf_node_flag
FROM eni_item_vbh_nodes_v e
WHERE e.parent_id =&ITEM+ENI_ITEM_VBH_CAT
AND e.id = e.child_id
AND ((e.leaf_node_flag=''N'' AND e.parent_id<>e.id) OR e.leaf_node_flag=''Y'')
) p
WHERE f.effective_time_id=c.time_id
AND f.parent_sales_group_id = &ORGANIZATION+JTF_ORG_SALES_GROUP
AND f.effective_period_type_id=c.period_type_id
AND f.product_category_id = edh.child_id
AND edh.object_type = ''CATEGORY_SET''
AND edh.object_id = mdc.category_set_id
AND mdc.functional_area_id = 11
AND edh.dbi_flag = ''Y''
AND edh.parent_id = p.id
AND c.calendar_id=-1
AND c.report_date in (&BIS_CURRENT_ASOF_DATE,&BIS_PREVIOUS_ASOF_DATE)
AND BITAND(c.record_type_id,:l_record_type)=c.record_type_id
GROUP BY p.value,p.id,p.leaf_node_flag
UNION ALL/******Directly Assigned to Category*******/
SELECT /*+ leading(c) */
bim_pmv_dbi_utl_pkg.get_lookup_value('||''''||'DASS'||''''||')'||' BIM_SALES_GROUP,
p.id VIEWBYID,
''Y'' leaf_node_flag,
sum(decode(c.report_date,&BIS_CURRENT_ASOF_DATE,cnv_opty_amt'||l_curr_suffix||',0)) oppt_amt,
sum(decode(c.report_date,&BIS_PREVIOUS_ASOF_DATE,cnv_opty_amt'||l_curr_suffix||',0)) prev_oppt_amt,
0,0,0,0,0
FROM FII_TIME_RPT_STRUCT c, bil_bi_opty_pg_mv f
, (SELECT e.id id,e.value value
FROM eni_item_vbh_nodes_v e
WHERE e.parent_id = &ITEM+ENI_ITEM_VBH_CAT
AND e.parent_id = e.child_id
AND leaf_node_flag <> ''Y''
) p
WHERE f.effective_time_id=c.time_id
AND f.parent_sales_group_id = &ORGANIZATION+JTF_ORG_SALES_GROUP
AND f.effective_period_type_id=c.period_type_id
--AND f.salesrep_id is null
AND f.product_category_id=p.id
AND c.calendar_id=-1
AND c.report_date in (&BIS_CURRENT_ASOF_DATE,&BIS_PREVIOUS_ASOF_DATE)
AND BITAND(c.record_type_id,:l_record_type)=c.record_type_id
GROUP BY p.value,p.id
)
GROUP BY BIM_SALES_GROUP,VIEWBYID,leaf_node_flag
HAVING
sum(leads_converted) > 0
OR sum(leads_new) > 0
OR sum(prev_open)> 0
OR sum(oppt_amt) > 0
OR sum(prev_oppt_amt) > 0
OR sum(conversion_time) > 0
OR sum(prev_lead_converted) > 0
)';
/* If Only rep is selected */
l_query := 'SELECT BIM_SALES_GROUP VIEWBY,
VIEWBYID,
oppt_amt BIM_ATTRIBUTE1,
decode(prev_oppt_amt,0,NULL,((oppt_amt - prev_oppt_amt)/prev_oppt_amt)*100) BIM_ATTRIBUTE2,
leads_converted BIM_ATTRIBUTE3,
DECODE(leads_converted,0,NULL,conversion_time/leads_converted) BIM_ATTRIBUTE4,
DECODE((prev_open+leads_new),0,NULL,(leads_converted/(prev_open+leads_new))*100) BIM_ATTRIBUTE5,
DECODE(prev_lead_converted,0,NULL,((leads_converted - prev_lead_converted)/prev_lead_converted)*100) BIM_ATTRIBUTE6,
NULL BIM_ATTRIBUTE13,
DECODE(leaf_node_flag,''Y'',NULL,'||''''||l_url_str||''''||' ) BIM_ATTRIBUTE15,
oppt_amt BIM_ATTRIBUTE16,
DECODE((prev_open+leads_new),0,NULL,(leads_converted/(prev_open+leads_new))*100) BIM_ATTRIBUTE17,
SUM(oppt_amt) OVER() BIM_GRAND_TOTAL1,
DECODE(sum(prev_oppt_amt) over(),0,NULL,(sum(oppt_amt - prev_oppt_amt) over()/sum(prev_oppt_amt) over())*100) BIM_GRAND_TOTAL2,
SUM(leads_converted) OVER() BIM_GRAND_TOTAL3,
DECODE(sum(leads_converted) over(),0,NULL,sum(conversion_time) over()/sum(leads_converted) over()) BIM_GRAND_TOTAL4,
DECODE(sum(open_new) over(),0,NULL,(sum(leads_converted) over()/sum(open_new) over())*100) BIM_GRAND_TOTAL5
FROM (
SELECT
BIM_SALES_GROUP,
VIEWBYID,
leaf_node_flag,
sum(oppt_amt) oppt_amt,
sum(prev_oppt_amt) prev_oppt_amt,
sum(leads_new) leads_new,
sum(leads_converted) leads_converted,
sum(prev_open+leads_new) open_new,
sum(conversion_time) conversion_time,
sum(prev_open) prev_open,
sum(prev_lead_converted) prev_lead_converted
FROM
(
/*********children of the selected category*********/
SELECT /*+ leading(c) */
p.value BIM_SALES_GROUP,
p.id VIEWBYID,
p.leaf_node_flag leaf_node_flag,
0 oppt_amt,
0 prev_oppt_amt,
sum(decode(c.report_date,&BIS_CURRENT_ASOF_DATE,leads_new,0)) leads_new,
sum(decode(c.report_date,&BIS_CURRENT_ASOF_DATE,leads_converted,0)) leads_converted,
sum(decode(c.report_date,&BIS_CURRENT_ASOF_DATE,conversion_time,0)) conversion_time,
0 prev_open,
sum(decode(c.report_date,&BIS_PREVIOUS_ASOF_DATE,leads_converted,0)) prev_lead_converted
FROM FII_TIME_RPT_STRUCT c, BIM_I_LP_GEN_SG_MV b
,eni_denorm_hierarchies edh
,mtl_default_category_sets mdc
,(SELECT e.id,e.value,leaf_node_flag
FROM eni_item_vbh_nodes_v e
WHERE e.parent_id =&ITEM+ENI_ITEM_VBH_CAT
AND e.id = e.child_id
AND ((e.leaf_node_flag=''N'' AND e.parent_id<>e.id) OR e.leaf_node_flag=''Y'')
) p
WHERE b.group_id = :l_group_id
AND b.product_category_id = edh.child_id
AND edh.object_type = ''CATEGORY_SET''
AND edh.object_id = mdc.category_set_id
AND mdc.functional_area_id = 11
AND edh.dbi_flag = ''Y''
AND edh.parent_id = p.id
AND c.calendar_id=-1
AND c.report_date in (&BIS_CURRENT_ASOF_DATE,&BIS_PREVIOUS_ASOF_DATE)
AND BITAND(c.record_type_id,:l_record_type)=c.record_type_id
AND b.time_id=c.time_id
AND b.period_type_id=c.period_type_id
AND b.update_period_type_id = -1
AND b.update_time_id = -1
AND b.resource_id = :l_resource_id
GROUP BY p.value,p.id,p.leaf_node_flag
UNION ALL
select /*+ leading(c) */
p.value BIM_SALES_GROUP,
p.id VIEWBYID,
p.leaf_node_flag leaf_node_flag,
0 oppt_amt,
0 prev_oppt_amt,
0 leads_new,
0 leads_converted,
0 conversion_time,
sum(b.leads-(b.leads_closed+b.leads_dead+b.leads_converted)) prev_open,
0 prev_lead_converted
FROM FII_TIME_RPT_STRUCT c, BIM_I_LP_GEN_SG_MV b
,eni_denorm_hierarchies edh
,mtl_default_category_sets mdc
,(SELECT e.id,e.value,leaf_node_flag
FROM eni_item_vbh_nodes_v e
WHERE e.parent_id =&ITEM+ENI_ITEM_VBH_CAT
AND e.id = e.child_id
AND ((e.leaf_node_flag=''N'' AND e.parent_id<>e.id) OR e.leaf_node_flag=''Y'')
) p
WHERE b.group_id = :l_group_id
AND b.product_category_id = edh.child_id
AND edh.object_type = ''CATEGORY_SET''
AND edh.object_id = mdc.category_set_id
AND mdc.functional_area_id = 11
AND edh.dbi_flag = ''Y''
AND edh.parent_id = p.id
AND c.calendar_id=-1
AND c.report_date = &BIS_CURRENT_EFFECTIVE_START_DATE - 1
AND BITAND(c.record_type_id,1143)=c.record_type_id
AND b.time_id=c.time_id
AND b.period_type_id=c.period_type_id
AND b.update_period_type_id = -1
AND b.update_time_id = -1
AND b.resource_id = :l_resource_id
HAVING sum(b.leads-(b.leads_closed+b.leads_dead+b.leads_converted)) <> 0
GROUP BY p.value,p.id,p.leaf_node_flag
UNION ALL
/******Directly Assigned to Category*******/
SELECT /*+ leading(c) */
bim_pmv_dbi_utl_pkg.get_lookup_value('||''''||'DASS'||''''||')'||' BIM_SALES_GROUP,
p.id VIEWBYID,
''Y'' leaf_node_flag,
0 oppt_amt,
0 prev_oppt_amt,
sum(decode(c.report_date,&BIS_CURRENT_ASOF_DATE,leads_new,0)) leads_new,
sum(decode(c.report_date,&BIS_CURRENT_ASOF_DATE,leads_converted,0)) leads_converted,
sum(decode(c.report_date,&BIS_CURRENT_ASOF_DATE,conversion_time,0)) conversion_time,
0 prev_open,
sum(decode(c.report_date,&BIS_PREVIOUS_ASOF_DATE,leads_converted,0)) prev_lead_converted
FROM FII_TIME_RPT_STRUCT c, BIM_I_LP_GEN_SG_MV b
,(SELECT e.id id,e.value value
FROM eni_item_vbh_nodes_v e
WHERE e.parent_id = &ITEM+ENI_ITEM_VBH_CAT
AND e.parent_id = e.child_id
AND leaf_node_flag <> ''Y''
) p
WHERE b.group_id = :l_group_id
AND p.id = b.product_category_id
AND c.calendar_id=-1
AND c.report_date in (&BIS_CURRENT_ASOF_DATE,&BIS_PREVIOUS_ASOF_DATE)
AND BITAND(c.record_type_id,:l_record_type)=c.record_type_id
AND b.time_id=c.time_id
AND b.period_type_id=c.period_type_id
AND b.update_period_type_id = -1
AND b.update_time_id = -1
AND b.resource_id = :l_resource_id
AND b.item_id = ''-1''
GROUP BY p.value,p.id
UNION ALL
select /*+ leading(c) */
bim_pmv_dbi_utl_pkg.get_lookup_value('||''''||'DASS'||''''||')'||' BIM_SALES_GROUP,
p.id VIEWBYID,
''Y'' leaf_node_flag,
0 oppt_amt,
0 prev_oppt_amt,
0 leads_new,
0 leads_converted,
0 conversion_time,
sum(b.leads-(b.leads_closed+b.leads_dead+b.leads_converted)) prev_open,
0 prev_lead_converted
FROM FII_TIME_RPT_STRUCT c, BIM_I_LP_GEN_SG_MV b
,(SELECT e.id id,e.value value
FROM eni_item_vbh_nodes_v e
WHERE e.parent_id = &ITEM+ENI_ITEM_VBH_CAT
AND e.parent_id = e.child_id
AND leaf_node_flag <> ''Y''
) p
WHERE b.group_id = :l_group_id
AND p.id = b.product_category_id
AND c.calendar_id=-1
AND c.report_date = &BIS_CURRENT_EFFECTIVE_START_DATE - 1
AND BITAND(c.record_type_id,1143)=c.record_type_id
AND b.time_id=c.time_id
AND b.period_type_id=c.period_type_id
AND b.update_period_type_id = -1
AND b.update_time_id = -1
AND b.resource_id = :l_resource_id
AND b.item_id = ''-1''
GROUP BY p.value,p.id
HAVING sum(b.leads-(b.leads_closed+b.leads_dead+b.leads_converted)) <> 0
UNION ALL /*********children of the selected category*********/
SELECT /*+ leading(c) */
p.value BIM_SALES_GROUP,
p.id VIEWBYID,
p.leaf_node_flag leaf_node_flag,
sum(decode(c.report_date,&BIS_CURRENT_ASOF_DATE,cnv_opty_amt'||l_curr_suffix||',0)) oppt_amt,
sum(decode(c.report_date,&BIS_PREVIOUS_ASOF_DATE,cnv_opty_amt'||l_curr_suffix||',0)) prev_oppt_amt,
0,0,0,0,0
FROM FII_TIME_RPT_STRUCT c, bil_bi_opty_pg_mv f
,eni_denorm_hierarchies edh
,mtl_default_category_sets mdc
,(select e.id,e.value,leaf_node_flag
from eni_item_vbh_nodes_v e
where e.parent_id =&ITEM+ENI_ITEM_VBH_CAT
AND e.id = e.child_id
AND ((e.leaf_node_flag=''N'' AND e.parent_id<>e.id) OR e.leaf_node_flag=''Y'')
) p
WHERE f.effective_time_id=c.time_id
AND f.parent_sales_group_id = :l_group_id
AND f.effective_period_type_id=c.period_type_id
AND f.product_category_id = edh.child_id
AND edh.object_type = ''CATEGORY_SET''
AND edh.object_id = mdc.category_set_id
AND mdc.functional_area_id = 11
AND edh.dbi_flag = ''Y''
AND edh.parent_id = p.id AND f.salesrep_id = :l_resource_id
AND c.calendar_id=-1
AND c.report_date in (&BIS_CURRENT_ASOF_DATE,&BIS_PREVIOUS_ASOF_DATE)
AND BITAND(c.record_type_id,:l_record_type)=c.record_type_id
GROUP BY p.value,p.id,p.leaf_node_flag
UNION ALL /******Directly Assigned to Category*******/
SELECT /*+ leading(c) */
bim_pmv_dbi_utl_pkg.get_lookup_value('||''''||'DASS'||''''||')'||' BIM_SALES_GROUP,
p.id VIEWBYID,
''Y'' leaf_node_flag,
sum(decode(c.report_date,&BIS_CURRENT_ASOF_DATE,cnv_opty_amt'||l_curr_suffix||',0)) oppt_amt,
sum(decode(c.report_date,&BIS_PREVIOUS_ASOF_DATE,cnv_opty_amt'||l_curr_suffix||',0)) prev_oppt_amt,
0,0,0,0,0
FROM FII_TIME_RPT_STRUCT c, bil_bi_opty_pg_mv f
,(SELECT e.id id,e.value value
FROM eni_item_vbh_nodes_v e
WHERE e.parent_id = &ITEM+ENI_ITEM_VBH_CAT
AND e.parent_id = e.child_id
AND leaf_node_flag <> ''Y''
) p
WHERE f.effective_time_id=c.time_id
AND f.parent_sales_group_id = :l_group_id
AND f.effective_period_type_id=c.period_type_id
AND f.product_category_id=p.id
AND f.salesrep_id = :l_resource_id
AND c.calendar_id=-1
AND c.report_date in (&BIS_CURRENT_ASOF_DATE,&BIS_PREVIOUS_ASOF_DATE)
AND BITAND(c.record_type_id,:l_record_type)=c.record_type_id
GROUP BY p.value,p.id
)
GROUP BY BIM_SALES_GROUP,VIEWBYID,leaf_node_flag
HAVING
sum(leads_converted) > 0
OR sum(leads_new) > 0
OR sum(prev_open)> 0
OR sum(oppt_amt) > 0
OR sum(prev_oppt_amt) > 0
OR sum(conversion_time) > 0
OR sum(prev_lead_converted) > 0
)';
l_query := 'SELECT BIM_SALES_GROUP VIEWBY,
VIEWBYID,
oppt_amt BIM_ATTRIBUTE1,
decode(prev_oppt_amt,0,NULL,((oppt_amt - prev_oppt_amt)/prev_oppt_amt)*100) BIM_ATTRIBUTE2,
leads_converted BIM_ATTRIBUTE3,
DECODE(leads_converted,0,NULL,conversion_time/leads_converted) BIM_ATTRIBUTE4,
DECODE((prev_open+leads_new),0,NULL,(leads_converted/(prev_open+leads_new))*100) BIM_ATTRIBUTE5,
DECODE(prev_lead_converted,0,NULL,((leads_converted - prev_lead_converted)/prev_lead_converted)*100) BIM_ATTRIBUTE6,
DECODE(is_resource,1,NULL,'||''''||l_url_str||''''||' ) BIM_ATTRIBUTE13,
NULL BIM_ATTRIBUTE15,
oppt_amt BIM_ATTRIBUTE16,
DECODE((prev_open+leads_new),0,NULL,(leads_converted/(prev_open+leads_new))*100) BIM_ATTRIBUTE17,
SUM(oppt_amt) OVER() BIM_GRAND_TOTAL1,
DECODE(sum(prev_oppt_amt) over(),0,NULL,(sum(oppt_amt - prev_oppt_amt) over()/sum(prev_oppt_amt) over())*100) BIM_GRAND_TOTAL2,
SUM(leads_converted) OVER() BIM_GRAND_TOTAL3,
DECODE(sum(leads_converted) over(),0,NULL,sum(conversion_time) over()/sum(leads_converted) over()) BIM_GRAND_TOTAL4,
DECODE(sum(open_new) over(),0,NULL,(sum(leads_converted) over()/sum(open_new) over())*100) BIM_GRAND_TOTAL5
FROM
(
SELECT
BIM_SALES_GROUP,
VIEWBYID,
is_resource,
sum(oppt_amt) oppt_amt,
sum(prev_oppt_amt) prev_oppt_amt,
sum(leads_new) leads_new,
sum(leads_converted) leads_converted,
sum(prev_open+leads_new) open_new,
sum(conversion_time) conversion_time,
sum(prev_open) prev_open,
sum(prev_lead_converted) prev_lead_converted
FROM
(
select d.group_name BIM_SALES_GROUP,VIEWBYID,is_resource,oppt_amt,prev_oppt_amt,
leads_new,leads_converted, conversion_time,prev_open,prev_lead_converted
from (
SELECT '||l_hint||'
'||l_col1_a||' group_id,
to_char( '||l_col2_a||' ) VIEWBYID,
'||l_col3_a||' is_resource,
0 oppt_amt,
0 prev_oppt_amt,
sum(decode(c.report_date,&BIS_CURRENT_ASOF_DATE,leads_new,0)) leads_new,
sum(decode(c.report_date,&BIS_CURRENT_ASOF_DATE,leads_converted,0)) leads_converted,
sum(decode(c.report_date,&BIS_CURRENT_ASOF_DATE,conversion_time,0)) conversion_time,
0 prev_open,
sum(decode(c.report_date,&BIS_PREVIOUS_ASOF_DATE,leads_converted,0)) prev_lead_converted
FROM FII_TIME_RPT_STRUCT c , jtf_rs_groups_denorm den, '|| l_tables_a|| '
WHERE den.parent_group_id in (&ORGANIZATION+JTF_ORG_SALES_GROUP)
and den.group_id=b.group_id
AND den.immediate_parent_flag = ''Y''
AND den.latest_relationship_flag = ''Y''
AND c.calendar_id=-1
AND c.report_date in (&BIS_CURRENT_ASOF_DATE,&BIS_PREVIOUS_ASOF_DATE)
AND BITAND(c.record_type_id,:l_record_type)=c.record_type_id
'||l_where_a||'
GROUP BY '||l_col1_a||','||l_col2_a||','||l_col3_a||'
/*prior open*/
UNION ALL
select '||l_hint||'
'||l_col1_e||' group_id,
to_char( '||l_col2_e||' ) VIEWBYID,
'||l_col3_e||' is_resource,
0 oppt_amt,
0 prev_oppt_amt,
0 leads_new,
0 leads_converted,
0 conversion_time,
sum(b.leads - (leads_closed+leads_dead+leads_converted)) prev_open,
0 prev_lead_converted
FROM FII_TIME_RPT_STRUCT c, jtf_rs_groups_denorm den, '|| l_tables_e|| '
WHERE den.parent_group_id in (&ORGANIZATION+JTF_ORG_SALES_GROUP)
and den.group_id=b.group_id
AND den.immediate_parent_flag = ''Y''
AND den.latest_relationship_flag = ''Y''
AND c.calendar_id=-1
AND c.report_date = &BIS_CURRENT_EFFECTIVE_START_DATE - 1
AND BITAND(c.record_type_id,1143)=c.record_type_id
'||l_where_e||'
GROUP BY '||l_col1_e||','||l_col2_e||','||l_col3_e||'
HAVING sum(b.leads-(leads_closed+leads_dead+leads_converted)) <> 0
UNION ALL/* For Oppurtunity Info from Sales MVs*/
SELECT /*+ leading(c) */ b.sales_group_id group_id ,to_char(b.sales_group_id),0,
sum(decode(c.report_date,&BIS_CURRENT_ASOF_DATE,cnv_opty_amt'||l_curr_suffix||',0)) oppt_amt,
sum(decode(c.report_date,&BIS_PREVIOUS_ASOF_DATE,cnv_opty_amt'||l_curr_suffix||',0)) prev_oppt_amt,0,0,0,0,0
FROM FII_TIME_RPT_STRUCT c , '||l_sg_table||'
WHERE c.calendar_id=-1
AND c.report_date in (&BIS_CURRENT_ASOF_DATE,&BIS_PREVIOUS_ASOF_DATE)
AND BITAND(c.record_type_id,:l_record_type)=c.record_type_id
AND b.effective_time_id =c.time_id
AND b.parent_sales_group_id = &ORGANIZATION+JTF_ORG_SALES_GROUP
AND b.effective_period_type_id=c.period_type_id
AND b.salesrep_id is null
'||l_sg_and||'
GROUP BY b.sales_group_id,b.sales_group_id,0
----
) q, jtf_rs_groups_tl d where
q.group_id=d.group_id
AND d.language=USERENV(''LANG'')
---------------------------------------------------------------
UNION ALL
-----------------------------------------------------------------
/* Leads Converted for reps*/
select d.source_name BIM_SALES_GROUP,VIEWBYID,is_resource,oppt_amt,prev_oppt_amt,
leads_new,leads_converted, conversion_time,prev_open,prev_lead_converted
from (
SELECT '||l_hint||'
'||l_col1_c||' resource_id,
to_char( '||l_col2_c||' ) VIEWBYID,
'||l_col3_c||' is_resource,
0 oppt_amt,
0 prev_oppt_amt,
sum(decode(c.report_date,&BIS_CURRENT_ASOF_DATE,leads_new,0)) leads_new,
sum(decode(c.report_date,&BIS_CURRENT_ASOF_DATE,leads_converted,0)) leads_converted,
sum(decode(c.report_date,&BIS_CURRENT_ASOF_DATE,conversion_time,0)) conversion_time,
0 prev_open,
sum(decode(c.report_date,&BIS_PREVIOUS_ASOF_DATE,leads_converted,0)) prev_lead_converted
FROM FII_TIME_RPT_STRUCT c , '|| l_tables_C|| '
WHERE c.calendar_id=-1
AND c.report_date in (&BIS_CURRENT_ASOF_DATE,&BIS_PREVIOUS_ASOF_DATE)
AND BITAND(c.record_type_id,:l_record_type)=c.record_type_id
'||l_where_c||'
GROUP BY '||l_col1_c||','||l_col2_c||','||l_col3_c||'
UNION ALL
/* prior Open for reps*/
SELECT '||l_hint||'
'||l_col1_f||' resource_id,
to_char( '||l_col2_f||' ) VIEWBYID,
'||l_col3_f||' is_resource,
0 oppt_amt,
0 prev_oppt_amt,
0 leads_new,
0 leads_converted,
0 conversion_time,
sum(b.leads - (leads_closed+leads_dead+leads_converted)) prev_open,
0 prev_lead_converted
FROM FII_TIME_RPT_STRUCT c , '|| l_tables_f|| '
WHERE c.calendar_id=-1
AND c.report_date = &BIS_CURRENT_EFFECTIVE_START_DATE - 1
AND BITAND(c.record_type_id,1143)=c.record_type_id
'||l_where_f||'
GROUP BY '||l_col1_f||','||l_col2_f||','||l_col3_f||'
HAVING sum(b.leads-(leads_closed+leads_dead+leads_converted)) <> 0
UNION ALL/* For Reps*/
SELECT /*+ leading(c) */ b.salesrep_id resource_id,to_char(b.salesrep_id||''.''||b.sales_group_id),1,
sum(decode(c.report_date,&BIS_CURRENT_ASOF_DATE,cnv_opty_amt'||l_curr_suffix||',0)) oppt_amt,
sum(decode(c.report_date,&BIS_PREVIOUS_ASOF_DATE,cnv_opty_amt'||l_curr_suffix||',0)) prev_oppt_amt,0,0,0,0,0
FROM FII_TIME_RPT_STRUCT c , '||l_sg_table||'
WHERE c.calendar_id=-1
AND c.report_date in (&BIS_CURRENT_ASOF_DATE,&BIS_PREVIOUS_ASOF_DATE)
AND BITAND(c.record_type_id,:l_record_type)=c.record_type_id
AND b.effective_time_id=c.time_id
AND b.parent_sales_group_id = &ORGANIZATION+JTF_ORG_SALES_GROUP
AND b.effective_period_type_id=c.period_type_id
AND b.salesrep_id is not null '||l_sg_and||'
GROUP BY b.salesrep_id,b.salesrep_id||''.''||b.sales_group_id,1
----
) q, JTF_RS_RESOURCE_EXTNS_VL d where
q.resource_id=d.resource_id
)
GROUP BY BIM_SALES_GROUP,VIEWBYID,is_resource
HAVING
sum(leads_converted) > 0
OR sum(leads_new) > 0
OR sum(prev_open) > 0
OR sum(oppt_amt) > 0
OR sum(prev_oppt_amt) > 0
OR sum(conversion_time) > 0
OR sum(prev_lead_converted) > 0
) ';
l_query := 'SELECT BIM_SALES_GROUP VIEWBY,
VIEWBYID,
oppt_amt BIM_ATTRIBUTE1,
decode(prev_oppt_amt,0,NULL,((oppt_amt - prev_oppt_amt)/prev_oppt_amt)*100) BIM_ATTRIBUTE2,
leads_converted BIM_ATTRIBUTE3,
DECODE(leads_converted,0,NULL,conversion_time/leads_converted) BIM_ATTRIBUTE4,
DECODE((prev_open+leads_new),0,NULL,(leads_converted/(prev_open+leads_new))*100) BIM_ATTRIBUTE5,
DECODE(prev_lead_converted,0,NULL,((leads_converted - prev_lead_converted)/prev_lead_converted)*100) BIM_ATTRIBUTE6,
DECODE(is_resource,1,NULL,'||''''||l_url_str||''''||' ) BIM_ATTRIBUTE13,
NULL BIM_ATTRIBUTE15,
oppt_amt BIM_ATTRIBUTE16,
DECODE((prev_open+leads_new),0,NULL,(leads_converted/(prev_open+leads_new))*100) BIM_ATTRIBUTE17,
SUM(oppt_amt) OVER() BIM_GRAND_TOTAL1,
DECODE(sum(prev_oppt_amt) over(),0,NULL,(sum(oppt_amt - prev_oppt_amt) over()/sum(prev_oppt_amt) over())*100) BIM_GRAND_TOTAL2,
SUM(leads_converted) OVER() BIM_GRAND_TOTAL3,
DECODE(sum(leads_converted) over(),0,NULL,sum(conversion_time) over()/sum(leads_converted) over()) BIM_GRAND_TOTAL4,
DECODE(sum(open_new) over(),0,NULL,(sum(leads_converted) over()/sum(open_new) over())*100) BIM_GRAND_TOTAL5
FROM
(
SELECT
d.source_name BIM_SALES_GROUP,
VIEWBYID,
is_resource,
sum(oppt_amt) oppt_amt,
sum(prev_oppt_amt) prev_oppt_amt,
sum(leads_new) leads_new,
sum(leads_converted) leads_converted,
sum(prev_open+leads_new) open_new,
sum(conversion_time) conversion_time,
sum(prev_open) prev_open,
sum(prev_lead_converted) prev_lead_converted
FROM
(
/* Leads Converted for reps*/
SELECT '||l_hint||'
'||l_col1_c||' resource_id,
to_char( '||l_col2_c||' ) VIEWBYID,
'||l_col3_c||' is_resource,
0 oppt_amt,
0 prev_oppt_amt,
sum(decode(c.report_date,&BIS_CURRENT_ASOF_DATE,leads_new,0)) leads_new,
sum(decode(c.report_date,&BIS_CURRENT_ASOF_DATE,leads_converted,0)) leads_converted,
sum(decode(c.report_date,&BIS_CURRENT_ASOF_DATE,conversion_time,0)) conversion_time,
0 prev_open,
sum(decode(c.report_date,&BIS_PREVIOUS_ASOF_DATE,leads_converted,0)) prev_lead_converted
FROM FII_TIME_RPT_STRUCT c, '|| l_tables_c|| '
WHERE c.calendar_id=-1
AND c.report_date in (&BIS_CURRENT_ASOF_DATE,&BIS_PREVIOUS_ASOF_DATE)
AND BITAND(c.record_type_id,:l_record_type)=c.record_type_id
'||l_where_c||'
GROUP BY '||l_col1_c||','||l_col2_c||','||l_col3_c||'
/* Previous */
UNION ALL
/* prior Open for reps*/
SELECT '||l_hint||'
'||l_col1_f||' resource_id,
to_char( '||l_col2_f||' ) VIEWBYID,
'||l_col3_f||' is_resource,
0 oppt_amt,
0 prev_oppt_amt,
0 leads_new,
0 leads_converted,
0 conversion_time,
sum(b.leads - (leads_closed+leads_dead+leads_converted)) prev_open,
0 prev_lead_converted
FROM FII_TIME_RPT_STRUCT c , '|| l_tables_f|| '
WHERE c.calendar_id=-1
AND c.report_date = &BIS_CURRENT_EFFECTIVE_START_DATE - 1
AND BITAND(c.record_type_id,1143)=c.record_type_id
'||l_where_f||'
GROUP BY '||l_col1_f||','||l_col2_f||','||l_col3_f||'
having sum(b.leads - (leads_closed+leads_dead+leads_converted)) <> 0
or sum(leads_converted) <> 0
UNION ALL /* For Oppurtunity Info from Sales MVs*/
/* For Reps*/
SELECT /*+ leading(c) */ b.salesrep_id resource_id,to_char(b.salesrep_id||''.''||b.sales_group_id),1,
sum(decode(c.report_date,&BIS_CURRENT_ASOF_DATE,cnv_opty_amt'||l_curr_suffix||',0)) oppt_amt,
sum(decode(c.report_date,&BIS_PREVIOUS_ASOF_DATE,cnv_opty_amt'||l_curr_suffix||',0)) prev_oppt_amt,0,0,0,0,0
FROM FII_TIME_RPT_STRUCT c , '||l_sg_table||'
WHERE b.effective_time_id=c.time_id
AND b.parent_sales_group_id = :l_group_id
AND b.effective_period_type_id=c.period_type_id
AND b.salesrep_id is not null
AND b.salesrep_id = :l_resource_id
AND c.calendar_id=-1
AND c.report_date in (&BIS_CURRENT_ASOF_DATE,&BIS_PREVIOUS_ASOF_DATE)
AND BITAND(c.record_type_id,:l_record_type)=c.record_type_id '||l_sg_and||'
GROUP BY b.salesrep_id,b.salesrep_id||''.''||b.sales_group_id,1
)q,
JTF_RS_RESOURCE_EXTNS_VL d where
q.resource_id=d.resource_id
GROUP BY d.source_name,VIEWBYID,is_resource
HAVING
sum(leads_converted) > 0
OR sum(leads_new) > 0
OR sum(prev_open) > 0
OR sum(oppt_amt) > 0
OR sum(prev_oppt_amt) > 0
OR sum(conversion_time) > 0
OR sum(prev_lead_converted) > 0
) ';
l_query := 'SELECT
NULL VIEWBY,
NULL VIEWBYID,
NULL BIM_MEASURE1,
NULL BIM_MEASURE2,
NULL BIM_MEASURE3,
NULL BIM_MEASURE4,
NULL BIM_MEASURE5,
NULL BIM_MEASURE6,
NULL BIM_MEASURE8,
NULL BIM_MEASURE7,
NULL BIM_MEASURE9,
NULL BIM_URL1,
NULL BIM_URL2,
NULL BIM_URL3,
NULL BIM_URL4,
NULL BIM_URL5,
NULL BIM_URL6,
NULL BIM_URL7,
NULL BIM_GRAND_TOTAL1,
NULL BIM_GRAND_TOTAL2,
NULL BIM_GRAND_TOTAL3,
NULL BIM_GRAND_TOTAL4,
NULL BIM_GRAND_TOTAL5,
NULL BIM_GRAND_TOTAL6,
NULL bim_GRAND_TOTAL7,
NULL bim_GRAND_TOTAL8,
NULL bim_GRAND_TOTAL9
FROM dual ';
AND b.update_time_id= -1
AND b.update_period_type_id= -1
AND b.resource_id = :l_resource_id ';
AND b.update_time_id=c.time_id
AND b.update_period_type_id=c.period_type_id
and b.time_id = :l_time_id
and b.period_type_id = :l_period_type_id
AND b.resource_id = :l_resource_id ';
AND b.update_time_id= -1
AND b.update_period_type_id= -1
AND b.resource_id <> :l_resource_id ';
AND b.update_time_id=c.time_id
AND b.update_period_type_id=c.period_type_id
and b.time_id = :l_time_id
and b.period_type_id = :l_period_type_id
AND b.resource_id <> :l_resource_id ';
AND b.update_time_id= -1
AND b.update_period_type_id= -1
AND b.resource_id = :l_resource_id ';
AND b.update_time_id= -1
AND b.update_period_type_id= -1
AND b.resource_id <> :l_resource_id ';
AND b.update_time_id=c.time_id
AND b.update_period_type_id=c.period_type_id
and b.time_id = :l_prev_time_id
and b.period_type_id = :l_period_type_id
AND b.resource_id <> :l_resource_id ';
AND b.update_time_id=c.time_id
AND b.update_period_type_id=c.period_type_id
and b.time_id = :l_prev_time_id
and b.period_type_id = :l_period_type_id
AND b.resource_id = :l_resource_id ';
AND b.update_time_id= -1
AND b.update_period_type_id= -1
AND b.resource_id = :l_resource_id ' ;
AND b.update_time_id=c.time_id
AND b.update_period_type_id=c.period_type_id
and b.time_id = :l_time_id
and b.period_type_id = :l_period_type_id
AND b.resource_id = :l_resource_id ' ;
AND b.update_time_id= -1
AND b.update_period_type_id= -1
AND b.resource_id = :l_resource_id ' ;
AND b.update_time_id=c.time_id
AND b.update_period_type_id=c.period_type_id
and b.time_id = :l_prev_time_id
and b.period_type_id = :l_period_type_id
AND b.resource_id = :l_resource_id ' ;
AND b.update_period_type_id = -1
AND b.update_time_id = -1
AND b.resource_id = :l_resource_id
AND b.product_category_id = edh.child_id AND edh.object_type = ''CATEGORY_SET'' AND edh.object_id = mtl.category_set_id AND mtl.functional_area_id = 11 AND edh.dbi_flag = ''Y'' AND edh.parent_id = &ITEM+ENI_ITEM_VBH_CAT ';
AND b.update_time_id=c.time_id
AND b.update_period_type_id=c.period_type_id
and b.time_id = :l_time_id
and b.period_type_id = :l_period_type_id
AND b.resource_id = :l_resource_id
AND b.product_category_id = edh.child_id AND edh.object_type = ''CATEGORY_SET'' AND edh.object_id = mtl.category_set_id AND mtl.functional_area_id = 11 AND edh.dbi_flag = ''Y'' AND edh.parent_id = &ITEM+ENI_ITEM_VBH_CAT ';
AND b.update_period_type_id = -1
AND b.update_time_id = -1
AND b.resource_id <> :l_resource_id ';
AND b.update_time_id=c.time_id
AND b.update_period_type_id=c.period_type_id
and b.time_id = :l_time_id
and b.period_type_id = :l_period_type_id
AND b.resource_id <> :l_resource_id ';
AND b.update_period_type_id = -1
AND b.update_time_id = -1
AND b.resource_id = :l_resource_id
AND b.product_category_id = edh.child_id AND edh.object_type = ''CATEGORY_SET'' AND edh.object_id = mtl.category_set_id AND mtl.functional_area_id = 11 AND edh.dbi_flag = ''Y'' AND edh.parent_id = &ITEM+ENI_ITEM_VBH_CAT ';
AND b.update_period_type_id = -1
AND b.update_time_id = -1
AND b.resource_id <> :l_resource_id
AND b.product_category_id = edh.child_id AND edh.object_type = ''CATEGORY_SET'' AND edh.object_id = mtl.category_set_id AND mtl.functional_area_id = 11 AND edh.dbi_flag = ''Y'' AND edh.parent_id = &ITEM+ENI_ITEM_VBH_CAT ';
AND b.update_time_id=c.time_id
AND b.update_period_type_id=c.period_type_id
and b.time_id = :l_prev_time_id
and b.period_type_id = :l_period_type_id
AND b.resource_id <> :l_resource_id ';
AND b.update_time_id=c.time_id
AND b.update_period_type_id=c.period_type_id
and b.time_id = :l_prev_time_id
and b.period_type_id = :l_period_type_id
AND b.resource_id =:l_resource_id
AND b.product_category_id = edh.child_id AND edh.object_type = ''CATEGORY_SET'' AND edh.object_id = mtl.category_set_id AND mtl.functional_area_id = 11 AND edh.dbi_flag = ''Y'' AND edh.parent_id = &ITEM+ENI_ITEM_VBH_CAT ';
AND b.update_period_type_id = -1
AND b.update_time_id = -1
AND b.resource_id = :l_resource_id ' ;
AND b.update_time_id=c.time_id
AND b.update_period_type_id=c.period_type_id
and b.time_id = :l_time_id
and b.period_type_id = :l_period_type_id
AND b.resource_id = :l_resource_id ';
AND b.update_period_type_id = -1
AND b.update_time_id = -1
AND b.resource_id = :l_resource_id
AND b.product_category_id = edh.child_id AND edh.object_type = ''CATEGORY_SET'' AND edh.object_id = mtl.category_set_id AND mtl.functional_area_id = 11 AND edh.dbi_flag = ''Y'' AND edh.parent_id = &ITEM+ENI_ITEM_VBH_CAT ';
AND b.update_time_id=c.time_id
AND b.update_period_type_id=c.period_type_id
and b.time_id = :l_prev_time_id
and b.period_type_id = :l_period_type_id
AND b.resource_id = :l_resource_id ';
/* If Only group is selected and rep is not selected */
if (l_resource_id is null) THEN
l_query := 'SELECT BIM_SALES_GROUP VIEWBY,
VIEWBYID,
leads_converted BIM_ATTRIBUTE1,
DECODE((prev_open+leads_new),0,NULL,(leads_converted/(prev_open+leads_new))*100) BIM_ATTRIBUTE2,
DECODE(leads_new,0,NULL,(leads_new_conv/leads_new)*100) BIM_ATTRIBUTE3,
DECODE(leads_converted,0,NULL,conversion_time/leads_converted) BIM_ATTRIBUTE4,
leads_new_conv BIM_ATTRIBUTE5,
DECODE(prev_lead_converted,0,NULL,((leads_converted - prev_lead_converted)/prev_lead_converted)*100) BIM_ATTRIBUTE6,
DECODE(prev_new_lead_converted,0,NULL,((leads_new_conv - prev_new_lead_converted)/prev_new_lead_converted)*100) BIM_ATTRIBUTE7,
NULL BIM_ATTRIBUTE12,
DECODE(leaf_node_flag,''Y'',NULL,'||''''||l_url_str||''''||' ) BIM_ATTRIBUTE13,
SUM(leads_converted) OVER() BIM_GRAND_TOTAL1,
DECODE(sum(prev_open+leads_new) over(),0,NULL,(sum(leads_converted) over()/sum(prev_open+leads_new) over())*100) BIM_GRAND_TOTAL2,
DECODE(sum(leads_new) over(),0,NULL,(sum(leads_new_conv) over()/sum(leads_new) over())*100) BIM_GRAND_TOTAL3,
DECODE(sum(leads_converted) over(),0,NULL,sum(conversion_time) over()/sum(leads_converted) over()) BIM_GRAND_TOTAL4,
sum(leads_new_conv) over() BIM_GRAND_TOTAL5,
DECODE(sum(prev_lead_converted) over(),0,NULL,(( sum(leads_converted - prev_lead_converted) over() )/sum(prev_lead_converted) over())*100) BIM_GRAND_TOTAL6,
DECODE(sum(prev_new_lead_converted) over(),0,NULL,((sum(leads_new_conv - prev_new_lead_converted) over())/sum(prev_new_lead_converted) over())*100) BIM_GRAND_TOTAL7
FROM (
SELECT
BIM_SALES_GROUP,
VIEWBYID,
leaf_node_flag,
sum(leads_new) leads_new,
sum(leads_converted) leads_converted,
sum(leads_new_conv) leads_new_conv,
sum(conversion_time) conversion_time,
sum(prev_open) prev_open,
sum(prev_lead_converted) prev_lead_converted,
sum(prev_new_lead_converted) prev_new_lead_converted
FROM
(
SELECT /*+ leading(c) */
p.value BIM_SALES_GROUP,
p.parent_id VIEWBYID,
p.leaf_node_flag leaf_node_flag,
sum(decode(c.report_date,&BIS_CURRENT_ASOF_DATE,leads_new,0)) leads_new,
sum(decode(c.report_date,&BIS_CURRENT_ASOF_DATE,leads_converted,0)) leads_converted,
0 leads_new_conv,
sum(decode(c.report_date,&BIS_CURRENT_ASOF_DATE,conversion_time,0)) conversion_time,
0 prev_open,
sum(decode(c.report_date,&BIS_PREVIOUS_ASOF_DATE,leads_converted,0)) prev_lead_converted,
0 prev_new_lead_converted
FROM FII_TIME_RPT_STRUCT c, BIM_I_LP_GEN_SG_MV b,( SELECT e.parent_id parent_id ,e.value value,e.leaf_node_flag leaf_node_flag
FROM eni_item_vbh_nodes_v e
WHERE e.top_node_flag=''Y''
AND e.child_id = e.parent_id) p
,eni_denorm_hierarchies edh
,mtl_default_category_sets d
WHERE
b.group_id = &ORGANIZATION+JTF_ORG_SALES_GROUP
AND b.product_category_id = edh.child_id
AND edh.object_type = ''CATEGORY_SET''
AND edh.object_id = d.category_set_id
AND d.functional_area_id = 11
AND edh.dbi_flag = ''Y''
AND edh.parent_id = p.parent_id
AND c.calendar_id=-1
AND c.report_date in (&BIS_CURRENT_ASOF_DATE,&BIS_PREVIOUS_ASOF_DATE)
AND BITAND(c.record_type_id,:l_record_type)=c.record_type_id
AND b.time_id=c.time_id
AND b.period_type_id=c.period_type_id
AND b.update_period_type_id = -1
AND b.update_time_id = -1
AND b.resource_id = :l_resource_id
GROUP BY p.value,p.parent_id,p.leaf_node_flag
UNION ALL
/*current leads new conv for groups*/
SELECT /*+ leading(c) */
p.value BIM_SALES_GROUP,
p.parent_id VIEWBYID,
p.leaf_node_flag leaf_node_flag,
0 leads_new,
0 leads_converted,
sum(leads_new_conv) leads_new_conv,
0 conversion_time,
0 prev_open,
0 prev_lead_converted,
0 prev_new_lead_converted
FROM FII_TIME_RPT_STRUCT c, BIM_I_LP_GEN_SG_MV b,( SELECT e.parent_id parent_id ,e.value value,e.leaf_node_flag leaf_node_flag
FROM eni_item_vbh_nodes_v e
WHERE e.top_node_flag=''Y''
AND e.child_id = e.parent_id) p
,eni_denorm_hierarchies edh
,mtl_default_category_sets d
WHERE
b.group_id = &ORGANIZATION+JTF_ORG_SALES_GROUP
AND b.product_category_id = edh.child_id
AND edh.object_type = ''CATEGORY_SET''
AND edh.object_id = d.category_set_id
AND d.functional_area_id = 11
AND edh.dbi_flag = ''Y''
AND edh.parent_id = p.parent_id
AND c.calendar_id=-1
AND c.report_date =&BIS_CURRENT_ASOF_DATE
AND BITAND(c.record_type_id,1143)=c.record_type_id
AND b.update_time_id=c.time_id
AND b.update_period_type_id=c.period_type_id
and b.time_id = :l_time_id
and b.period_type_id = :l_period_type_id
AND b.resource_id = :l_resource_id
GROUP BY p.value,p.parent_id,p.leaf_node_flag
UNION ALL
/*previous leads new conv for groups*/
SELECT /*+ leading(c) */
p.value BIM_SALES_GROUP,
p.parent_id VIEWBYID,
p.leaf_node_flag leaf_node_flag,
0 leads_new,
0 leads_converted,
0 leads_new_conv,
0 conversion_time,
0 prev_open,
0 prev_lead_converted,
sum(leads_new_conv) prev_new_lead_converted
FROM FII_TIME_RPT_STRUCT c, BIM_I_LP_GEN_SG_MV b,( SELECT e.parent_id parent_id ,e.value value,e.leaf_node_flag leaf_node_flag
FROM eni_item_vbh_nodes_v e
WHERE e.top_node_flag=''Y''
AND e.child_id = e.parent_id) p
,eni_denorm_hierarchies edh
,mtl_default_category_sets d
WHERE
b.group_id = &ORGANIZATION+JTF_ORG_SALES_GROUP
AND b.product_category_id = edh.child_id
AND edh.object_type = ''CATEGORY_SET''
AND edh.object_id = d.category_set_id
AND d.functional_area_id = 11
AND edh.dbi_flag = ''Y''
AND edh.parent_id = p.parent_id
AND c.calendar_id=-1
AND c.report_date =&BIS_PREVIOUS_ASOF_DATE
AND BITAND(c.record_type_id,1143)=c.record_type_id
AND b.update_time_id=c.time_id
AND b.update_period_type_id=c.period_type_id
and b.time_id = :l_prev_time_id
and b.period_type_id = :l_period_type_id
AND b.resource_id =:l_resource_id
GROUP BY p.value,p.parent_id,p.leaf_node_flag
UNION ALL
select /*+ leading(c) */
p.value BIM_SALES_GROUP,
p.parent_id VIEWBYID,
p.leaf_node_flag leaf_node_flag,
0 leads_new,
0 leads_converted,
0 leads_new_conv,
0 conversion_time,
sum(b.leads-(b.leads_closed+b.leads_dead+b.leads_converted)) prev_open,
0 prev_lead_converted,
0 prev_new_lead_converted
FROM FII_TIME_RPT_STRUCT c, BIM_I_LP_GEN_SG_MV b,( SELECT e.parent_id parent_id ,e.value value,e.leaf_node_flag leaf_node_flag
FROM eni_item_vbh_nodes_v e
WHERE e.top_node_flag=''Y''
AND e.child_id = e.parent_id) p
,eni_denorm_hierarchies edh
,mtl_default_category_sets d
WHERE
b.group_id = &ORGANIZATION+JTF_ORG_SALES_GROUP
AND b.product_category_id = edh.child_id
AND edh.object_type = ''CATEGORY_SET''
AND edh.object_id = d.category_set_id
AND d.functional_area_id = 11
AND edh.dbi_flag = ''Y''
AND edh.parent_id = p.parent_id
AND c.calendar_id=-1
AND c.report_date = &BIS_CURRENT_EFFECTIVE_START_DATE - 1
AND BITAND(c.record_type_id,1143)=c.record_type_id
AND b.time_id=c.time_id
AND b.period_type_id=c.period_type_id
AND b.update_period_type_id = -1
AND b.update_time_id = -1
AND b.resource_id = :l_resource_id
AND (b.leads-(b.leads_closed+b.leads_dead+b.leads_converted)) <> 0
GROUP BY p.value,p.parent_id,p.leaf_node_flag
)
GROUP BY BIM_SALES_GROUP,VIEWBYID,leaf_node_flag
HAVING
sum(leads_converted) > 0
OR sum(leads_new) > 0
OR sum(prev_open)> 0
OR sum(leads_new_conv) > 0
OR sum(conversion_time) > 0
OR sum(prev_lead_converted) > 0
OR sum(prev_new_lead_converted) > 0
)';
/* If Only rep is selected */
l_query := 'SELECT BIM_SALES_GROUP VIEWBY,
VIEWBYID,
leads_converted BIM_ATTRIBUTE1,
DECODE((prev_open+leads_new),0,NULL,(leads_converted/(prev_open+leads_new))*100) BIM_ATTRIBUTE2,
DECODE(leads_new,0,NULL,(leads_new_conv/leads_new)*100) BIM_ATTRIBUTE3,
DECODE(leads_converted,0,NULL,conversion_time/leads_converted) BIM_ATTRIBUTE4,
leads_new_conv BIM_ATTRIBUTE5,
DECODE(prev_lead_converted,0,NULL,((leads_converted - prev_lead_converted)/prev_lead_converted)*100) BIM_ATTRIBUTE6,
DECODE(prev_new_lead_converted,0,NULL,((leads_new_conv - prev_new_lead_converted)/prev_new_lead_converted)*100) BIM_ATTRIBUTE7,
NULL BIM_ATTRIBUTE12,
DECODE(leaf_node_flag,''Y'',NULL,'||''''||l_url_str||''''||' ) BIM_ATTRIBUTE13,
SUM(leads_converted) OVER() BIM_GRAND_TOTAL1,
DECODE(sum(prev_open+leads_new) over(),0,NULL,(sum(leads_converted) over()/sum(prev_open+leads_new) over())*100) BIM_GRAND_TOTAL2,
DECODE(sum(leads_new) over(),0,NULL,(sum(leads_new_conv) over()/sum(leads_new) over())*100) BIM_GRAND_TOTAL3,
DECODE(sum(leads_converted) over(),0,NULL,sum(conversion_time) over()/sum(leads_converted) over()) BIM_GRAND_TOTAL4,
sum(leads_new_conv) over() BIM_GRAND_TOTAL5,
DECODE(sum(prev_lead_converted) over(),0,NULL,(( sum(leads_converted - prev_lead_converted) over() )/sum(prev_lead_converted) over())*100) BIM_GRAND_TOTAL6,
DECODE(sum(prev_new_lead_converted) over(),0,NULL,((sum(leads_new_conv - prev_new_lead_converted) over())/sum(prev_new_lead_converted) over())*100) BIM_GRAND_TOTAL7
FROM (
SELECT
BIM_SALES_GROUP,
VIEWBYID,
leaf_node_flag,
sum(leads_new) leads_new,
sum(leads_converted) leads_converted,
sum(leads_new_conv) leads_new_conv,
sum(conversion_time) conversion_time,
sum(prev_open) prev_open,
sum(prev_lead_converted) prev_lead_converted,
sum(prev_new_lead_converted) prev_new_lead_converted
FROM
(
SELECT /*+ leading(c) */
p.value BIM_SALES_GROUP,
p.parent_id VIEWBYID,
p.leaf_node_flag leaf_node_flag,
sum(decode(c.report_date,&BIS_CURRENT_ASOF_DATE,leads_new,0)) leads_new,
sum(decode(c.report_date,&BIS_CURRENT_ASOF_DATE,leads_converted,0)) leads_converted,
0 leads_new_conv,
sum(decode(c.report_date,&BIS_CURRENT_ASOF_DATE,conversion_time,0)) conversion_time,
0 prev_open,
sum(decode(c.report_date,&BIS_PREVIOUS_ASOF_DATE,leads_converted,0)) prev_lead_converted,
0 prev_new_lead_converted
FROM FII_TIME_RPT_STRUCT c, BIM_I_LP_GEN_SG_MV b,( SELECT e.parent_id parent_id ,e.value value,e.leaf_node_flag leaf_node_flag
FROM eni_item_vbh_nodes_v e
WHERE e.top_node_flag=''Y''
AND e.child_id = e.parent_id) p
,eni_denorm_hierarchies edh
,mtl_default_category_sets d
WHERE
b.group_id = :l_group_id
AND b.product_category_id = edh.child_id
AND edh.object_type = ''CATEGORY_SET''
AND edh.object_id = d.category_set_id
AND d.functional_area_id = 11
AND edh.dbi_flag = ''Y''
AND edh.parent_id = p.parent_id
AND c.calendar_id=-1
AND c.report_date in (&BIS_CURRENT_ASOF_DATE,&BIS_PREVIOUS_ASOF_DATE)
AND BITAND(c.record_type_id,:l_record_type)=c.record_type_id
AND b.time_id=c.time_id
AND b.period_type_id=c.period_type_id
AND b.update_period_type_id = -1
AND b.update_time_id = -1
AND b.resource_id = :l_resource_id
GROUP BY p.value,p.parent_id,p.leaf_node_flag
UNION ALL
/*current leads new conv for groups*/
SELECT /*+ leading(c) */
p.value BIM_SALES_GROUP,
p.parent_id VIEWBYID,
p.leaf_node_flag leaf_node_flag,
0 leads_new,
0 leads_converted,
sum(leads_new_conv) leads_new_conv,
0 conversion_time,
0 prev_open,
0 prev_lead_converted,
0 prev_new_lead_converted
FROM FII_TIME_RPT_STRUCT c, BIM_I_LP_GEN_SG_MV b,( SELECT e.parent_id parent_id ,e.value value,e.leaf_node_flag leaf_node_flag
FROM eni_item_vbh_nodes_v e
WHERE e.top_node_flag=''Y''
AND e.child_id = e.parent_id) p
,eni_denorm_hierarchies edh
,mtl_default_category_sets d
WHERE
b.group_id = :l_group_id
AND b.product_category_id = edh.child_id
AND edh.object_type = ''CATEGORY_SET''
AND edh.object_id = d.category_set_id
AND d.functional_area_id = 11
AND edh.dbi_flag = ''Y''
AND edh.parent_id = p.parent_id
AND c.calendar_id=-1
AND c.report_date =&BIS_CURRENT_ASOF_DATE
AND BITAND(c.record_type_id,1143)=c.record_type_id
AND b.update_time_id=c.time_id
AND b.update_period_type_id=c.period_type_id
and b.time_id = :l_time_id
and b.period_type_id = :l_period_type_id
AND b.resource_id = :l_resource_id
GROUP BY p.value,p.parent_id,p.leaf_node_flag
UNION ALL
/*current leads new conv for groups*/
SELECT /*+ leading(c) */
p.value BIM_SALES_GROUP,
p.parent_id VIEWBYID,
p.leaf_node_flag leaf_node_flag,
0 leads_new,
0 leads_converted,
0 leads_new_conv,
0 conversion_time,
0 prev_open,
0 prev_lead_converted,
sum(leads_new_conv) prev_new_lead_converted
FROM FII_TIME_RPT_STRUCT c, BIM_I_LP_GEN_SG_MV b,( SELECT e.parent_id parent_id ,e.value value,e.leaf_node_flag leaf_node_flag
FROM eni_item_vbh_nodes_v e
WHERE e.top_node_flag=''Y''
AND e.child_id = e.parent_id) p
,eni_denorm_hierarchies edh
,mtl_default_category_sets d
WHERE
b.group_id = :l_group_id
AND b.product_category_id = edh.child_id
AND edh.object_type = ''CATEGORY_SET''
AND edh.object_id = d.category_set_id
AND d.functional_area_id = 11
AND edh.dbi_flag = ''Y''
AND edh.parent_id = p.parent_id
AND c.calendar_id=-1
AND c.report_date =&BIS_PREVIOUS_ASOF_DATE
AND BITAND(c.record_type_id,1143)=c.record_type_id
AND b.update_time_id=c.time_id
AND b.update_period_type_id=c.period_type_id
and b.time_id = :l_prev_time_id
and b.period_type_id = :l_period_type_id
AND b.resource_id = :l_resource_id
GROUP BY p.value,p.parent_id,p.leaf_node_flag
UNION ALL
select /*+ leading(c) */
p.value BIM_SALES_GROUP,
p.parent_id VIEWBYID,
p.leaf_node_flag leaf_node_flag,
0 leads_new,
0 leads_converted,
0 leads_new_conv,
0 conversion_time,
sum(b.leads-(b.leads_closed+b.leads_dead+b.leads_converted)) prev_open,
0 prev_lead_converted,
0 prev_new_lead_converted
FROM FII_TIME_RPT_STRUCT c, BIM_I_LP_GEN_SG_MV b,( SELECT e.parent_id parent_id ,e.value value,e.leaf_node_flag leaf_node_flag
FROM eni_item_vbh_nodes_v e
WHERE e.top_node_flag=''Y''
AND e.child_id = e.parent_id) p
,eni_denorm_hierarchies edh
,mtl_default_category_sets d
WHERE
b.group_id = :l_group_id
AND b.product_category_id = edh.child_id
AND edh.object_type = ''CATEGORY_SET''
AND edh.object_id = d.category_set_id
AND d.functional_area_id = 11
AND edh.dbi_flag = ''Y''
AND edh.parent_id = p.parent_id
AND c.calendar_id=-1
AND c.report_date = &BIS_CURRENT_EFFECTIVE_START_DATE - 1
AND BITAND(c.record_type_id,1143)=c.record_type_id
AND b.time_id=c.time_id
AND b.period_type_id=c.period_type_id
AND b.update_period_type_id = -1
AND b.update_time_id = -1
AND b.resource_id = :l_resource_id
AND (b.leads-(b.leads_closed+b.leads_dead+b.leads_converted)) <> 0
GROUP BY p.value,p.parent_id,p.leaf_node_flag
)
GROUP BY BIM_SALES_GROUP,VIEWBYID,leaf_node_flag
HAVING
sum(leads_converted) > 0
OR sum(leads_new) > 0
OR sum(prev_open)> 0
OR sum(leads_new_conv) > 0
OR sum(conversion_time) > 0
OR sum(prev_lead_converted) > 0
OR sum(prev_new_lead_converted) > 0
)';
/* If Only group is selected and rep is not selected */
if (l_resource_id is null) THEN
l_query := 'SELECT BIM_SALES_GROUP VIEWBY,
VIEWBYID,
leads_converted BIM_ATTRIBUTE1,
DECODE((prev_open+leads_new),0,NULL,(leads_converted/(prev_open+leads_new))*100) BIM_ATTRIBUTE2,
DECODE(leads_new,0,NULL,(leads_new_conv/leads_new)*100) BIM_ATTRIBUTE3,
DECODE(leads_converted,0,NULL,conversion_time/leads_converted) BIM_ATTRIBUTE4,
leads_new_conv BIM_ATTRIBUTE5,
DECODE(prev_lead_converted,0,NULL,((leads_converted - prev_lead_converted)/prev_lead_converted)*100) BIM_ATTRIBUTE6,
DECODE(prev_new_lead_converted,0,NULL,((leads_new_conv - prev_new_lead_converted)/prev_new_lead_converted)*100) BIM_ATTRIBUTE7,
NULL BIM_ATTRIBUTE12,
DECODE(leaf_node_flag,''Y'',NULL,'||''''||l_url_str||''''||' ) BIM_ATTRIBUTE13,
SUM(leads_converted) OVER() BIM_GRAND_TOTAL1,
DECODE(sum(prev_open+leads_new) over(),0,NULL,(sum(leads_converted) over()/sum(prev_open+leads_new) over())*100) BIM_GRAND_TOTAL2,
DECODE(sum(leads_new) over(),0,NULL,(sum(leads_new_conv) over()/sum(leads_new) over())*100) BIM_GRAND_TOTAL3,
DECODE(sum(leads_converted) over(),0,NULL,sum(conversion_time) over()/sum(leads_converted) over()) BIM_GRAND_TOTAL4,
sum(leads_new_conv) over() BIM_GRAND_TOTAL5,
DECODE(sum(prev_lead_converted) over(),0,NULL,(( sum(leads_converted - prev_lead_converted) over() )/sum(prev_lead_converted) over())*100) BIM_GRAND_TOTAL6,
DECODE(sum(prev_new_lead_converted) over(),0,NULL,((sum(leads_new_conv - prev_new_lead_converted) over())/sum(prev_new_lead_converted) over())*100) BIM_GRAND_TOTAL7
FROM (
SELECT
BIM_SALES_GROUP,
VIEWBYID,
leaf_node_flag,
sum(leads_new) leads_new,
sum(leads_converted) leads_converted,
sum(leads_new_conv) leads_new_conv,
sum(conversion_time) conversion_time,
sum(prev_open) prev_open,
sum(prev_lead_converted) prev_lead_converted,
sum(prev_new_lead_converted) prev_new_lead_converted
FROM
(
/*********children of the selected category*********/
SELECT /*+ leading(c) */
p.value BIM_SALES_GROUP,
p.id VIEWBYID,
p.leaf_node_flag leaf_node_flag,
sum(decode(c.report_date,&BIS_CURRENT_ASOF_DATE,leads_new,0)) leads_new,
sum(decode(c.report_date,&BIS_CURRENT_ASOF_DATE,leads_converted,0)) leads_converted,
0 leads_new_conv,
sum(decode(c.report_date,&BIS_CURRENT_ASOF_DATE,conversion_time,0)) conversion_time,
0 prev_open,
sum(decode(c.report_date,&BIS_PREVIOUS_ASOF_DATE,leads_converted,0)) prev_lead_converted,
0 prev_new_lead_converted
FROM FII_TIME_RPT_STRUCT c, BIM_I_LP_GEN_SG_MV b,eni_denorm_hierarchies edh
,mtl_default_category_sets mdc
,(select e.id,e.value,leaf_node_flag
from eni_item_vbh_nodes_v e
where
e.parent_id =&ITEM+ENI_ITEM_VBH_CAT
AND e.id = e.child_id
AND((e.leaf_node_flag=''N'' AND e.parent_id<>e.id) OR e.leaf_node_flag=''Y'')
) p
WHERE
b.group_id = &ORGANIZATION+JTF_ORG_SALES_GROUP
AND b.product_category_id = edh.child_id
AND edh.object_type = ''CATEGORY_SET''
AND edh.object_id = mdc.category_set_id
AND mdc.functional_area_id = 11
AND edh.dbi_flag = ''Y''
AND edh.parent_id = p.id
AND c.calendar_id=-1
AND c.report_date in (&BIS_CURRENT_ASOF_DATE,&BIS_PREVIOUS_ASOF_DATE)
AND BITAND(c.record_type_id,:l_record_type)=c.record_type_id
AND b.time_id=c.time_id
AND b.period_type_id=c.period_type_id
AND b.update_period_type_id = -1
AND b.update_time_id = -1
AND b.resource_id = :l_resource_id
GROUP BY p.value,p.id,p.leaf_node_flag
UNION ALL
/*leads new conv*/
SELECT /*+ leading(c) */
p.value BIM_SALES_GROUP,
p.id VIEWBYID,
p.leaf_node_flag leaf_node_flag,
0 leads_new,
0 leads_converted,
sum(leads_new_conv) leads_new_conv,
0 conversion_time,
0 prev_open,
0 prev_lead_converted,
0 prev_new_lead_converted
FROM FII_TIME_RPT_STRUCT c, BIM_I_LP_GEN_SG_MV b,eni_denorm_hierarchies edh
,mtl_default_category_sets mdc
,(select e.id,e.value,leaf_node_flag
from eni_item_vbh_nodes_v e
where
e.parent_id =&ITEM+ENI_ITEM_VBH_CAT
AND e.id = e.child_id
AND((e.leaf_node_flag=''N'' AND e.parent_id<>e.id) OR e.leaf_node_flag=''Y'')
) p
WHERE
b.group_id = &ORGANIZATION+JTF_ORG_SALES_GROUP
AND b.product_category_id = edh.child_id
AND edh.object_type = ''CATEGORY_SET''
AND edh.object_id = mdc.category_set_id
AND mdc.functional_area_id = 11
AND edh.dbi_flag = ''Y''
AND edh.parent_id = p.id
AND c.calendar_id=-1
AND c.report_date =&BIS_CURRENT_ASOF_DATE
AND BITAND(c.record_type_id,1143)=c.record_type_id
AND b.update_time_id=c.time_id
AND b.update_period_type_id=c.period_type_id
and b.time_id = :l_time_id
and b.period_type_id = :l_period_type_id
AND b.resource_id =:l_resource_id
GROUP BY p.value,p.id,p.leaf_node_flag
UNION ALL
SELECT /*+ leading(c) */
p.value BIM_SALES_GROUP,
p.id VIEWBYID,
p.leaf_node_flag leaf_node_flag,
0 leads_new,
0 leads_converted,
0 leads_new_conv,
0 conversion_time,
0 prev_open,
0 prev_lead_converted,
sum(leads_new_conv) prev_new_lead_converted
FROM FII_TIME_RPT_STRUCT c, BIM_I_LP_GEN_SG_MV b,eni_denorm_hierarchies edh
,mtl_default_category_sets mdc
,(select e.id,e.value,leaf_node_flag
from eni_item_vbh_nodes_v e
where
e.parent_id =&ITEM+ENI_ITEM_VBH_CAT
AND e.id = e.child_id
AND((e.leaf_node_flag=''N'' AND e.parent_id<>e.id) OR e.leaf_node_flag=''Y'')
) p
WHERE
b.group_id = &ORGANIZATION+JTF_ORG_SALES_GROUP
AND b.product_category_id = edh.child_id
AND edh.object_type = ''CATEGORY_SET''
AND edh.object_id = mdc.category_set_id
AND mdc.functional_area_id = 11
AND edh.dbi_flag = ''Y''
AND edh.parent_id = p.id
AND c.calendar_id=-1
AND c.report_date =&BIS_PREVIOUS_ASOF_DATE
AND BITAND(c.record_type_id,1143)=c.record_type_id
AND b.update_time_id=c.time_id
AND b.update_period_type_id=c.period_type_id
and b.time_id = :l_prev_time_id
and b.period_type_id = :l_period_type_id
AND b.resource_id = :l_resource_id
GROUP BY p.value,p.id,p.leaf_node_flag
UNION ALL
select /*+ leading(c) */
p.value BIM_SALES_GROUP,
p.id VIEWBYID,
p.leaf_node_flag leaf_node_flag,
0 leads_new,
0 leads_converted,
0 leads_new_conv,
0 conversion_time,
sum(b.leads-(b.leads_closed+b.leads_dead+b.leads_converted)) prev_open,
0 prev_lead_converted,
0 prev_new_lead_converted
FROM FII_TIME_RPT_STRUCT c, BIM_I_LP_GEN_SG_MV b,eni_denorm_hierarchies edh
,mtl_default_category_sets mdc
,(select e.id,e.value,leaf_node_flag
from eni_item_vbh_nodes_v e
where
e.parent_id =&ITEM+ENI_ITEM_VBH_CAT
AND e.id = e.child_id
AND((e.leaf_node_flag=''N'' AND e.parent_id<>e.id) OR e.leaf_node_flag=''Y'')
) p
WHERE
b.group_id = &ORGANIZATION+JTF_ORG_SALES_GROUP
AND b.product_category_id = edh.child_id
AND edh.object_type = ''CATEGORY_SET''
AND edh.object_id = mdc.category_set_id
AND mdc.functional_area_id = 11
AND edh.dbi_flag = ''Y''
AND edh.parent_id = p.id
AND c.calendar_id=-1
AND c.report_date = &BIS_CURRENT_EFFECTIVE_START_DATE - 1
AND BITAND(c.record_type_id,1143)=c.record_type_id
AND b.time_id=c.time_id
AND b.period_type_id=c.period_type_id
AND b.update_period_type_id = -1
AND b.update_time_id = -1
AND b.resource_id = :l_resource_id
AND (b.leads-(b.leads_closed+b.leads_dead+b.leads_converted)) <> 0
GROUP BY p.value,p.id,p.leaf_node_flag
UNION ALL
/******Directly Assigned to Category*******/
SELECT /*+ leading(c) */
bim_pmv_dbi_utl_pkg.get_lookup_value('||''''||'DASS'||''''||')'||' BIM_SALES_GROUP,
p.id VIEWBYID,
''Y'' leaf_node_flag,
sum(decode(c.report_date,&BIS_CURRENT_ASOF_DATE,leads_new,0)) leads_new,
sum(decode(c.report_date,&BIS_CURRENT_ASOF_DATE,leads_converted,0)) leads_converted,
0 leads_new_conv,
sum(decode(c.report_date,&BIS_CURRENT_ASOF_DATE,conversion_time,0)) conversion_time,
0 prev_open,
sum(decode(c.report_date,&BIS_PREVIOUS_ASOF_DATE,leads_converted,0)) prev_lead_converted,
0 prev_new_lead_converted
FROM FII_TIME_RPT_STRUCT c, BIM_I_LP_GEN_SG_MV b,(select e.id id,e.value value
from eni_item_vbh_nodes_v e
where e.parent_id = &ITEM+ENI_ITEM_VBH_CAT
AND e.parent_id = e.child_id
AND leaf_node_flag <> ''Y''
) p
WHERE
b.group_id = &ORGANIZATION+JTF_ORG_SALES_GROUP
AND p.id = b.product_category_id
AND c.calendar_id=-1
AND c.report_date in (&BIS_CURRENT_ASOF_DATE,&BIS_PREVIOUS_ASOF_DATE)
AND BITAND(c.record_type_id,:l_record_type)=c.record_type_id
AND b.time_id=c.time_id
AND b.period_type_id=c.period_type_id
AND b.update_period_type_id = -1
AND b.update_time_id = -1
AND b.resource_id = :l_resource_id
AND b.item_id = ''-1''
GROUP BY p.value,p.id
UNION ALL
/******Leads New Conv Directly Assigned to Category*******/
SELECT /*+ leading(c) */
bim_pmv_dbi_utl_pkg.get_lookup_value('||''''||'DASS'||''''||')'||' BIM_SALES_GROUP,
p.id VIEWBYID,
''Y'' leaf_node_flag,
0 leads_new,
0 leads_converted,
sum(leads_new_conv) leads_new_conv,
0 conversion_time,
0 prev_open,
0 prev_lead_converted,
0 prev_new_lead_converted
FROM FII_TIME_RPT_STRUCT c, BIM_I_LP_GEN_SG_MV b,(select e.id id,e.value value
from eni_item_vbh_nodes_v e
where e.parent_id = &ITEM+ENI_ITEM_VBH_CAT
AND e.parent_id = e.child_id
AND leaf_node_flag <> ''Y''
) p
WHERE
b.group_id = &ORGANIZATION+JTF_ORG_SALES_GROUP
AND p.id = b.product_category_id
AND c.calendar_id=-1
AND c.report_date =&BIS_CURRENT_ASOF_DATE
AND BITAND(c.record_type_id,1143)=c.record_type_id
AND b.update_time_id=c.time_id
AND b.update_period_type_id=c.period_type_id
and b.time_id = :l_time_id
and b.period_type_id = :l_period_type_id
AND b.resource_id = :l_resource_id
AND b.item_id = ''-1''
GROUP BY p.value,p.id
UNION ALL
/******Leads New Conv Directly Assigned to Category*******/
SELECT /*+ leading(c) */
bim_pmv_dbi_utl_pkg.get_lookup_value('||''''||'DASS'||''''||')'||' BIM_SALES_GROUP,
p.id VIEWBYID,
''Y'' leaf_node_flag,
0 leads_new,
0 leads_converted,
0 leads_new_conv,
0 conversion_time,
0 prev_open,
0 prev_lead_converted,
sum(leads_new_conv) prev_new_lead_converted
FROM FII_TIME_RPT_STRUCT c, BIM_I_LP_GEN_SG_MV b,(select e.id id,e.value value
from eni_item_vbh_nodes_v e
where e.parent_id = &ITEM+ENI_ITEM_VBH_CAT
AND e.parent_id = e.child_id
AND leaf_node_flag <> ''Y''
) p
WHERE
b.group_id = &ORGANIZATION+JTF_ORG_SALES_GROUP
AND p.id = b.product_category_id
AND c.calendar_id=-1
AND c.report_date =&BIS_PREVIOUS_ASOF_DATE
AND BITAND(c.record_type_id,1143)=c.record_type_id
AND b.update_time_id=c.time_id
AND b.update_period_type_id=c.period_type_id
and b.time_id = :l_prev_time_id
and b.period_type_id = :l_period_type_id
AND b.resource_id = :l_resource_id
AND b.item_id = ''-1''
GROUP BY p.value,p.id
UNION ALL
select /*+ leading(c) */
bim_pmv_dbi_utl_pkg.get_lookup_value('||''''||'DASS'||''''||')'||' BIM_SALES_GROUP,
p.id VIEWBYID,
''Y'' leaf_node_flag,
0 leads_new,
0 leads_converted,
0 leads_new_conv,
0 conversion_time,
sum(b.leads-(b.leads_closed+b.leads_dead+b.leads_converted)) prev_open,
0 prev_lead_converted,
0 prev_new_lead_converted
FROM FII_TIME_RPT_STRUCT c, BIM_I_LP_GEN_SG_MV b,(select e.id id,e.value value
from eni_item_vbh_nodes_v e
where e.parent_id = &ITEM+ENI_ITEM_VBH_CAT
AND e.parent_id = e.child_id
AND leaf_node_flag <> ''Y''
) p
WHERE
b.group_id = &ORGANIZATION+JTF_ORG_SALES_GROUP
AND p.id = b.product_category_id
AND c.calendar_id=-1
AND c.report_date = &BIS_CURRENT_EFFECTIVE_START_DATE - 1
AND BITAND(c.record_type_id,1143)=c.record_type_id
AND b.time_id=c.time_id
AND b.period_type_id=c.period_type_id
AND b.update_period_type_id = -1
AND b.update_time_id = -1
AND b.resource_id = :l_resource_id
AND b.item_id = ''-1''
AND (b.leads-(b.leads_closed+b.leads_dead+b.leads_converted)) <> 0
GROUP BY p.value,p.id
)
GROUP BY BIM_SALES_GROUP,VIEWBYID,leaf_node_flag
HAVING
sum(leads_converted) > 0
OR sum(leads_new) > 0
OR sum(prev_open)> 0
OR sum(leads_new_conv) > 0
OR sum(conversion_time) > 0
OR sum(prev_lead_converted) > 0
OR sum(prev_new_lead_converted) > 0
)';
/* If Only rep is selected */
l_query := 'SELECT BIM_SALES_GROUP VIEWBY,
VIEWBYID,
leads_converted BIM_ATTRIBUTE1,
DECODE((prev_open+leads_new),0,NULL,(leads_converted/(prev_open+leads_new))*100) BIM_ATTRIBUTE2,
DECODE(leads_new,0,NULL,(leads_new_conv/leads_new)*100) BIM_ATTRIBUTE3,
DECODE(leads_converted,0,NULL,conversion_time/leads_converted) BIM_ATTRIBUTE4,
leads_new_conv BIM_ATTRIBUTE5,
DECODE(prev_lead_converted,0,NULL,((leads_converted - prev_lead_converted)/prev_lead_converted)*100) BIM_ATTRIBUTE6,
DECODE(prev_new_lead_converted,0,NULL,((leads_new_conv - prev_new_lead_converted)/prev_new_lead_converted)*100) BIM_ATTRIBUTE7,
NULL BIM_ATTRIBUTE12,
DECODE(leaf_node_flag,''Y'',NULL,'||''''||l_url_str||''''||' ) BIM_ATTRIBUTE13,
SUM(leads_converted) OVER() BIM_GRAND_TOTAL1,
DECODE(sum(prev_open+leads_new) over(),0,NULL,(sum(leads_converted) over()/sum(prev_open+leads_new) over())*100) BIM_GRAND_TOTAL2,
DECODE(sum(leads_new) over(),0,NULL,(sum(leads_new_conv) over()/sum(leads_new) over())*100) BIM_GRAND_TOTAL3,
DECODE(sum(leads_converted) over(),0,NULL,sum(conversion_time) over()/sum(leads_converted) over()) BIM_GRAND_TOTAL4,
sum(leads_new_conv) over() BIM_GRAND_TOTAL5,
DECODE(sum(prev_lead_converted) over(),0,NULL,(( sum(leads_converted - prev_lead_converted) over() )/sum(prev_lead_converted) over())*100) BIM_GRAND_TOTAL6,
DECODE(sum(prev_new_lead_converted) over(),0,NULL,((sum(leads_new_conv - prev_new_lead_converted) over())/sum(prev_new_lead_converted) over())*100) BIM_GRAND_TOTAL7
FROM (
SELECT
BIM_SALES_GROUP,
VIEWBYID,
leaf_node_flag,
sum(leads_new) leads_new,
sum(leads_converted) leads_converted,
sum(leads_new_conv) leads_new_conv,
sum(conversion_time) conversion_time,
sum(prev_open) prev_open,
sum(prev_lead_converted) prev_lead_converted,
sum(prev_new_lead_converted) prev_new_lead_converted
FROM
(
/*********children of the selected category*********/
SELECT /*+ leading(c) */
p.value BIM_SALES_GROUP,
p.id VIEWBYID,
p.leaf_node_flag leaf_node_flag,
sum(decode(c.report_date,&BIS_CURRENT_ASOF_DATE,leads_new,0)) leads_new,
sum(decode(c.report_date,&BIS_CURRENT_ASOF_DATE,leads_converted,0)) leads_converted,
0 leads_new_conv,
sum(decode(c.report_date,&BIS_CURRENT_ASOF_DATE,conversion_time,0)) conversion_time,
0 prev_open,
sum(decode(c.report_date,&BIS_PREVIOUS_ASOF_DATE,leads_converted,0)) prev_lead_converted,
0 prev_new_lead_converted
FROM FII_TIME_RPT_STRUCT c, BIM_I_LP_GEN_SG_MV b,eni_denorm_hierarchies edh
,mtl_default_category_sets mdc
,(select e.id,e.value,leaf_node_flag
from eni_item_vbh_nodes_v e
where
e.parent_id =&ITEM+ENI_ITEM_VBH_CAT
AND e.id = e.child_id
AND((e.leaf_node_flag=''N'' AND e.parent_id<>e.id) OR e.leaf_node_flag=''Y'')
) p
WHERE
b.group_id = :l_group_id
AND b.product_category_id = edh.child_id
AND edh.object_type = ''CATEGORY_SET''
AND edh.object_id = mdc.category_set_id
AND mdc.functional_area_id = 11
AND edh.dbi_flag = ''Y''
AND edh.parent_id = p.id
AND c.calendar_id=-1
AND c.report_date in (&BIS_CURRENT_ASOF_DATE,&BIS_PREVIOUS_ASOF_DATE)
AND BITAND(c.record_type_id,:l_record_type)=c.record_type_id
AND b.time_id=c.time_id
AND b.period_type_id=c.period_type_id
AND b.update_period_type_id = -1
AND b.update_time_id = -1
AND b.resource_id = :l_resource_id
GROUP BY p.value,p.id,p.leaf_node_flag
UNION ALL
/*leads new conv*/
SELECT /*+ leading(c) */
p.value BIM_SALES_GROUP,
p.id VIEWBYID,
p.leaf_node_flag leaf_node_flag,
0 leads_new,
0 leads_converted,
sum(leads_new_conv) leads_new_conv,
0 conversion_time,
0 prev_open,
0 prev_lead_converted,
0 prev_new_lead_converted
FROM FII_TIME_RPT_STRUCT c, BIM_I_LP_GEN_SG_MV b,eni_denorm_hierarchies edh
,mtl_default_category_sets mdc
,(select e.id,e.value,leaf_node_flag
from eni_item_vbh_nodes_v e
where
e.parent_id =&ITEM+ENI_ITEM_VBH_CAT
AND e.id = e.child_id
AND((e.leaf_node_flag=''N'' AND e.parent_id<>e.id) OR e.leaf_node_flag=''Y'')
) p
WHERE
b.group_id = :l_group_id
AND b.product_category_id = edh.child_id
AND edh.object_type = ''CATEGORY_SET''
AND edh.object_id = mdc.category_set_id
AND mdc.functional_area_id = 11
AND edh.dbi_flag = ''Y''
AND edh.parent_id = p.id
AND c.calendar_id=-1
AND c.report_date = &BIS_CURRENT_ASOF_DATE
AND BITAND(c.record_type_id,1143)=c.record_type_id
AND b.update_time_id=c.time_id
AND b.update_period_type_id=c.period_type_id
and b.time_id = :l_time_id
and b.period_type_id = :l_period_type_id
AND b.resource_id = :l_resource_id
GROUP BY p.value,p.id,p.leaf_node_flag
UNION ALL
/*previous leads new conv*/
SELECT /*+ leading(c) */
p.value BIM_SALES_GROUP,
p.id VIEWBYID,
p.leaf_node_flag leaf_node_flag,
0 leads_new,
0 leads_converted,
0 leads_new_conv,
0 conversion_time,
0 prev_open,
0 prev_lead_converted,
sum(leads_new_conv) prev_new_lead_converted
FROM FII_TIME_RPT_STRUCT c, BIM_I_LP_GEN_SG_MV b,eni_denorm_hierarchies edh
,mtl_default_category_sets mdc
,(select e.id,e.value,leaf_node_flag
from eni_item_vbh_nodes_v e
where
e.parent_id =&ITEM+ENI_ITEM_VBH_CAT
AND e.id = e.child_id
AND((e.leaf_node_flag=''N'' AND e.parent_id<>e.id) OR e.leaf_node_flag=''Y'')
) p
WHERE
b.group_id = :l_group_id
AND b.product_category_id = edh.child_id
AND edh.object_type = ''CATEGORY_SET''
AND edh.object_id = mdc.category_set_id
AND mdc.functional_area_id = 11
AND edh.dbi_flag = ''Y''
AND edh.parent_id = p.id
AND c.calendar_id=-1
AND c.report_date = &BIS_PREVIOUS_ASOF_DATE
AND BITAND(c.record_type_id,1143)=c.record_type_id
AND b.update_time_id=c.time_id
AND b.update_period_type_id=c.period_type_id
and b.time_id = :l_prev_time_id
and b.period_type_id = :l_period_type_id
AND b.resource_id = :l_resource_id
GROUP BY p.value,p.id,p.leaf_node_flag
UNION ALL
select /*+ leading(c) */
p.value BIM_SALES_GROUP,
p.id VIEWBYID,
p.leaf_node_flag leaf_node_flag,
0 leads_new,
0 leads_converted,
0 leads_new_conv,
0 conversion_time,
sum(b.leads-(b.leads_closed+b.leads_dead+b.leads_converted)) prev_open,
0 prev_lead_converted,
0 prev_new_lead_converted
FROM FII_TIME_RPT_STRUCT c, BIM_I_LP_GEN_SG_MV b,eni_denorm_hierarchies edh
,mtl_default_category_sets mdc
,(select e.id,e.value,leaf_node_flag
from eni_item_vbh_nodes_v e
where
e.parent_id =&ITEM+ENI_ITEM_VBH_CAT
AND e.id = e.child_id
AND((e.leaf_node_flag=''N'' AND e.parent_id<>e.id) OR e.leaf_node_flag=''Y'')
) p
WHERE
b.group_id = :l_group_id
AND b.product_category_id = edh.child_id
AND edh.object_type = ''CATEGORY_SET''
AND edh.object_id = mdc.category_set_id
AND mdc.functional_area_id = 11
AND edh.dbi_flag = ''Y''
AND edh.parent_id = p.id
AND c.calendar_id=-1
AND c.report_date = &BIS_CURRENT_EFFECTIVE_START_DATE - 1
AND BITAND(c.record_type_id,1143)=c.record_type_id
AND b.time_id=c.time_id
AND b.period_type_id=c.period_type_id
AND b.update_period_type_id = -1
AND b.update_time_id = -1
AND b.resource_id = :l_resource_id
AND (b.leads-(b.leads_closed+b.leads_dead+b.leads_converted)) <> 0
GROUP BY p.value,p.id,p.leaf_node_flag
UNION ALL
/******Directly Assigned to Category*******/
SELECT /*+ leading(c) */
bim_pmv_dbi_utl_pkg.get_lookup_value('||''''||'DASS'||''''||')'||' BIM_SALES_GROUP,
p.id VIEWBYID,
''Y'' leaf_node_flag,
sum(decode(c.report_date,&BIS_CURRENT_ASOF_DATE,leads_new,0)) leads_new,
sum(decode(c.report_date,&BIS_CURRENT_ASOF_DATE,leads_converted,0)) leads_converted,
0 leads_new_conv,
sum(decode(c.report_date,&BIS_CURRENT_ASOF_DATE,conversion_time,0)) conversion_time,
0 prev_open,
sum(decode(c.report_date,&BIS_PREVIOUS_ASOF_DATE,leads_converted,0)) prev_lead_converted,
0 prev_new_lead_converted
FROM FII_TIME_RPT_STRUCT c, BIM_I_LP_GEN_SG_MV b,(select e.id id,e.value value
from eni_item_vbh_nodes_v e
where e.parent_id = &ITEM+ENI_ITEM_VBH_CAT
AND e.parent_id = e.child_id
AND leaf_node_flag <> ''Y''
) p
WHERE
b.group_id = :l_group_id
AND p.id = b.product_category_id
AND c.calendar_id=-1
AND c.report_date in (&BIS_CURRENT_ASOF_DATE,&BIS_PREVIOUS_ASOF_DATE)
AND BITAND(c.record_type_id,:l_record_type)=c.record_type_id
AND b.time_id=c.time_id
AND b.period_type_id=c.period_type_id
AND b.update_period_type_id = -1
AND b.update_time_id = -1
AND b.resource_id = :l_resource_id
AND b.item_id = ''-1''
GROUP BY p.value,p.id
UNION ALL
/******Leads New Conv Directly Assigned to Category*******/
SELECT /*+ leading(c) */
bim_pmv_dbi_utl_pkg.get_lookup_value('||''''||'DASS'||''''||')'||' BIM_SALES_GROUP,
p.id VIEWBYID,
''Y'' leaf_node_flag,
0 leads_new,
0 leads_converted,
sum(leads_new_conv) leads_new_conv,
0 conversion_time,
0 prev_open,
0 prev_lead_converted,
0 prev_new_lead_converted
FROM FII_TIME_RPT_STRUCT c, BIM_I_LP_GEN_SG_MV b,(select e.id id,e.value value
from eni_item_vbh_nodes_v e
where e.parent_id = &ITEM+ENI_ITEM_VBH_CAT
AND e.parent_id = e.child_id
AND leaf_node_flag <> ''Y''
) p
WHERE
b.group_id = :l_group_id
AND p.id = b.product_category_id
AND c.calendar_id=-1
AND c.report_date = &BIS_CURRENT_ASOF_DATE
AND BITAND(c.record_type_id,1143)=c.record_type_id
AND b.update_time_id=c.time_id
AND b.update_period_type_id=c.period_type_id
and b.time_id = :l_time_id
and b.period_type_id = :l_period_type_id
AND b.resource_id = :l_resource_id
AND b.item_id = ''-1''
GROUP BY p.value,p.id
UNION ALL
/******Leads New Conv Directly Assigned to Category*******/
SELECT /*+ leading(c) */
bim_pmv_dbi_utl_pkg.get_lookup_value('||''''||'DASS'||''''||')'||' BIM_SALES_GROUP,
p.id VIEWBYID,
''Y'' leaf_node_flag,
0 leads_new,
0 leads_converted,
0 leads_new_conv,
0 conversion_time,
0 prev_open,
0 prev_lead_converted,
sum(leads_new_conv) prev_new_lead_converted
FROM FII_TIME_RPT_STRUCT c, BIM_I_LP_GEN_SG_MV b,(select e.id id,e.value value
from eni_item_vbh_nodes_v e
where e.parent_id = &ITEM+ENI_ITEM_VBH_CAT
AND e.parent_id = e.child_id
AND leaf_node_flag <> ''Y''
) p
WHERE
b.group_id = :l_group_id
AND p.id = b.product_category_id
AND c.calendar_id=-1
AND c.report_date =&BIS_PREVIOUS_ASOF_DATE
AND BITAND(c.record_type_id,1143)=c.record_type_id
AND b.update_time_id=c.time_id
AND b.update_period_type_id=c.period_type_id
and b.time_id = :l_prev_time_id
and b.period_type_id = :l_period_type_id
AND b.resource_id = :l_resource_id
AND b.item_id = ''-1''
GROUP BY p.value,p.id
UNION ALL
select /*+ leading(c) */
bim_pmv_dbi_utl_pkg.get_lookup_value('||''''||'DASS'||''''||')'||' BIM_SALES_GROUP,
p.id VIEWBYID,
''Y'' leaf_node_flag,
0 leads_new,
0 leads_converted,
0 leads_new_conv,
0 conversion_time,
sum(b.leads-(b.leads_closed+b.leads_dead+b.leads_converted)) prev_open,
0 prev_lead_converted,
0 prev_new_lead_converted
FROM FII_TIME_RPT_STRUCT c, BIM_I_LP_GEN_SG_MV b,(select e.id id,e.value value
from eni_item_vbh_nodes_v e
where e.parent_id = &ITEM+ENI_ITEM_VBH_CAT
AND e.parent_id = e.child_id
AND leaf_node_flag <> ''Y''
) p
WHERE
b.group_id = :l_group_id
AND p.id = b.product_category_id
AND c.calendar_id=-1
AND c.report_date = &BIS_CURRENT_EFFECTIVE_START_DATE - 1
AND BITAND(c.record_type_id,1143)=c.record_type_id
AND b.time_id=c.time_id
AND b.period_type_id=c.period_type_id
AND b.update_period_type_id = -1
AND b.update_time_id = -1
AND b.resource_id = :l_resource_id
AND b.item_id = ''-1''
AND (b.leads-(b.leads_closed+b.leads_dead+b.leads_converted)) <> 0
GROUP BY p.value,p.id
)
GROUP BY BIM_SALES_GROUP,VIEWBYID,leaf_node_flag
HAVING
sum(leads_converted) > 0
OR sum(leads_new) > 0
OR sum(prev_open)> 0
OR sum(leads_new_conv) > 0
OR sum(conversion_time) > 0
OR sum(prev_lead_converted) > 0
OR sum(prev_new_lead_converted) > 0
)';
AND b.update_time_id= -1
AND b.update_period_type_id= -1
AND b.resource_id = :l_resource_id ';
AND b.update_time_id=c.time_id
AND b.update_period_type_id=c.period_type_id
and b.time_id = :l_time_id
and b.period_type_id = :l_period_type_id
AND b.resource_id =:l_resource_id ';
AND b.update_time_id=c.time_id
AND b.update_period_type_id=c.period_type_id
and b.time_id = :l_prev_time_id
and b.period_type_id = :l_period_type_id
AND b.resource_id = :l_resource_id ';
AND b.update_time_id= -1
AND b.update_period_type_id= -1
AND b.resource_id = :l_resource_id ';
AND b.update_time_id= -1
AND b.update_period_type_id= -1
AND b.resource_id = :l_resource_id ' ;
AND b.update_time_id=c.time_id
AND b.update_period_type_id=c.period_type_id
and b.time_id = :l_time_id
and b.period_type_id = :l_period_type_id
AND b.resource_id = :l_resource_id ' ;
AND b.update_time_id=c.time_id
AND b.update_period_type_id=c.period_type_id
and b.time_id = :l_prev_time_id
and b.period_type_id = :l_period_type_id
AND b.resource_id = :l_resource_id ' ;
AND b.update_time_id= -1
AND b.update_period_type_id= -1
AND b.resource_id = :l_resource_id ' ;
AND b.update_period_type_id = -1
AND b.update_time_id = -1
AND b.resource_id = :l_resource_id
AND b.product_category_id = edh.child_id AND edh.object_type = ''CATEGORY_SET'' AND edh.object_id = mtl.category_set_id
AND mtl.functional_area_id = 11 AND edh.dbi_flag = ''Y'' AND edh.parent_id = &ITEM+ENI_ITEM_VBH_CAT ';
AND b.update_time_id=c.time_id
AND b.update_period_type_id=c.period_type_id
and b.time_id = :l_time_id
and b.period_type_id = :l_period_type_id
AND b.resource_id = :l_resource_id
AND b.product_category_id = edh.child_id AND edh.object_type = ''CATEGORY_SET'' AND edh.object_id = mtl.category_set_id
AND mtl.functional_area_id = 11 AND edh.dbi_flag = ''Y'' AND edh.parent_id = &ITEM+ENI_ITEM_VBH_CAT ';
AND b.update_time_id=c.time_id
AND b.update_period_type_id=c.period_type_id
and b.time_id = :l_prev_time_id
and b.period_type_id = :l_period_type_id
AND b.resource_id = :l_resource_id
AND b.product_category_id = edh.child_id AND edh.object_type = ''CATEGORY_SET'' AND edh.object_id = mtl.category_set_id
AND mtl.functional_area_id = 11 AND edh.dbi_flag = ''Y'' AND edh.parent_id = &ITEM+ENI_ITEM_VBH_CAT ';
AND b.update_period_type_id = -1
AND b.update_time_id = -1
AND b.resource_id = :l_resource_id
AND b.product_category_id = edh.child_id AND edh.object_type = ''CATEGORY_SET'' AND edh.object_id = mtl.category_set_id
AND mtl.functional_area_id = 11 AND edh.dbi_flag = ''Y'' AND edh.parent_id = &ITEM+ENI_ITEM_VBH_CAT ';
AND b.update_period_type_id = -1
AND b.update_time_id = -1
AND b.resource_id = :l_resource_id ' ;
AND b.update_time_id=c.time_id
AND b.update_period_type_id=c.period_type_id
and b.time_id = :l_time_id
and b.period_type_id = :l_period_type_id
AND b.resource_id = :l_resource_id ';
AND b.update_time_id=c.time_id
AND b.update_period_type_id=c.period_type_id
and b.time_id = :l_prev_time_id
and b.period_type_id = :l_period_type_id
AND b.resource_id = :l_resource_id ';
AND b.update_period_type_id = -1
AND b.update_time_id = -1
AND b.resource_id = :l_resource_id
AND b.product_category_id = edh.child_id AND edh.object_type = ''CATEGORY_SET'' AND edh.object_id = mtl.category_set_id
AND mtl.functional_area_id = 11 AND edh.dbi_flag = ''Y'' AND edh.parent_id = &ITEM+ENI_ITEM_VBH_CAT ';
AND b.update_time_id= -1
AND b.update_period_type_id= -1
AND b.resource_id = :l_resource_id ';
AND b.update_time_id=c.time_id
AND b.update_period_type_id=c.period_type_id
and b.time_id = :l_time_id
and b.period_type_id = :l_period_type_id
AND b.resource_id = :l_resource_id ';
AND b.update_time_id=c.time_id
AND b.update_period_type_id=c.period_type_id
and b.time_id = :l_prev_time_id
and b.period_type_id = :l_period_type_id
AND b.resource_id = :l_resource_id ';
AND b.update_time_id= -1
AND b.update_period_type_id= -1
AND b.resource_id = :l_resource_id ';
AND b.update_time_id= -1
AND b.update_period_type_id= -1
AND b.resource_id = :l_resource_id ' ;
AND b.update_time_id=c.time_id
AND b.update_period_type_id=c.period_type_id
and b.time_id = :l_time_id
and b.period_type_id = :l_period_type_id
AND b.resource_id = :l_resource_id ' ;
AND b.update_time_id=c.time_id
AND b.update_period_type_id=c.period_type_id
and b.time_id = :l_prev_time_id
and b.period_type_id = :l_period_type_id
AND b.resource_id = :l_resource_id ' ;
AND b.update_time_id= -1
AND b.update_period_type_id= -1
AND b.resource_id = :l_resource_id ' ;
AND b.update_period_type_id = -1
AND b.update_time_id = -1
AND b.resource_id = :l_resource_id
AND b.product_category_id = edh.child_id AND edh.object_type = ''CATEGORY_SET'' AND edh.object_id = mtl.category_set_id
AND mtl.functional_area_id = 11 AND edh.dbi_flag = ''Y'' AND edh.parent_id = &ITEM+ENI_ITEM_VBH_CAT ';
AND b.update_time_id=c.time_id
AND b.update_period_type_id=c.period_type_id
and b.time_id = :l_time_id
and b.period_type_id = :l_period_type_id
AND b.resource_id = :l_resource_id
AND b.product_category_id = edh.child_id AND edh.object_type = ''CATEGORY_SET'' AND edh.object_id = mtl.category_set_id
AND mtl.functional_area_id = 11 AND edh.dbi_flag = ''Y'' AND edh.parent_id = &ITEM+ENI_ITEM_VBH_CAT ';
AND b.update_time_id=c.time_id
AND b.update_period_type_id=c.period_type_id
and b.time_id = :l_prev_time_id
and b.period_type_id = :l_period_type_id
AND b.resource_id = :l_resource_id
AND b.product_category_id = edh.child_id AND edh.object_type = ''CATEGORY_SET'' AND edh.object_id = mtl.category_set_id
AND mtl.functional_area_id = 11 AND edh.dbi_flag = ''Y'' AND edh.parent_id = &ITEM+ENI_ITEM_VBH_CAT ';
AND b.update_period_type_id = -1
AND b.update_time_id = -1
AND b.resource_id = :l_resource_id
AND b.product_category_id = edh.child_id AND edh.object_type = ''CATEGORY_SET'' AND edh.object_id = mtl.category_set_id
AND mtl.functional_area_id = 11 AND edh.dbi_flag = ''Y'' AND edh.parent_id = &ITEM+ENI_ITEM_VBH_CAT ';
AND b.update_period_type_id = -1
AND b.update_time_id = -1
AND b.resource_id = :l_resource_id ' ;
AND b.update_time_id=c.time_id
AND b.update_period_type_id=c.period_type_id
and b.time_id = :l_time_id
and b.period_type_id = :l_period_type_id
AND b.resource_id = :l_resource_id ';
AND b.update_time_id=c.time_id
AND b.update_period_type_id=c.period_type_id
and b.time_id = :l_prev_time_id
and b.period_type_id = :l_period_type_id
AND b.resource_id = :l_resource_id ';
AND b.update_period_type_id = -1
AND b.update_time_id = -1
AND b.resource_id = :l_resource_id
AND b.product_category_id = edh.child_id AND edh.object_type = ''CATEGORY_SET'' AND edh.object_id = mtl.category_set_id
AND mtl.functional_area_id = 11 AND edh.dbi_flag = ''Y'' AND edh.parent_id = &ITEM+ENI_ITEM_VBH_CAT ';
AND b.update_time_id= -1
AND b.update_period_type_id= -1
AND b.resource_id = :l_resource_id ';
AND b.update_time_id=c.time_id
AND b.update_period_type_id=c.period_type_id
and b.time_id = :l_time_id
and b.period_type_id = :l_period_type_id
AND b.resource_id = :l_resource_id ';
AND b.update_time_id=c.time_id
AND b.update_period_type_id=c.period_type_id
and b.time_id = :l_prev_time_id
and b.period_type_id = :l_period_type_id
AND b.resource_id = :l_resource_id ';
AND b.update_time_id= -1
AND b.update_period_type_id= -1
AND b.resource_id = :l_resource_id ';
AND b.update_time_id= -1
AND b.update_period_type_id= -1
AND b.resource_id = :l_resource_id ' ;
AND b.update_time_id=c.time_id
AND b.update_period_type_id=c.period_type_id
and b.time_id = :l_time_id
and b.period_type_id = :l_period_type_id
AND b.resource_id = :l_resource_id ' ;
AND b.update_time_id=c.time_id
AND b.update_period_type_id=c.period_type_id
and b.time_id = :l_prev_time_id
and b.period_type_id = :l_period_type_id
AND b.resource_id = :l_resource_id ' ;
AND b.update_time_id= -1
AND b.update_period_type_id= -1
AND b.resource_id = :l_resource_id ' ;
AND b.update_period_type_id = -1
AND b.update_time_id = -1
AND b.resource_id = :l_resource_id
AND b.product_category_id = edh.child_id AND edh.object_type = ''CATEGORY_SET'' AND edh.object_id = mtl.category_set_id
AND mtl.functional_area_id = 11 AND edh.dbi_flag = ''Y'' AND edh.parent_id = &ITEM+ENI_ITEM_VBH_CAT ';
AND b.update_time_id=c.time_id
AND b.update_period_type_id=c.period_type_id
and b.time_id = :l_time_id
and b.period_type_id = :l_period_type_id
AND b.resource_id = :l_resource_id
AND b.product_category_id = edh.child_id AND edh.object_type = ''CATEGORY_SET'' AND edh.object_id = mtl.category_set_id
AND mtl.functional_area_id = 11 AND edh.dbi_flag = ''Y'' AND edh.parent_id = &ITEM+ENI_ITEM_VBH_CAT ';
AND b.update_time_id=c.time_id
AND b.update_period_type_id=c.period_type_id
and b.time_id = :l_prev_time_id
and b.period_type_id = :l_period_type_id
AND b.resource_id =:l_resource_id
AND b.product_category_id = edh.child_id AND edh.object_type = ''CATEGORY_SET'' AND edh.object_id = mtl.category_set_id
AND mtl.functional_area_id = 11 AND edh.dbi_flag = ''Y'' AND edh.parent_id = &ITEM+ENI_ITEM_VBH_CAT ';
AND b.update_period_type_id = -1
AND b.update_time_id = -1
AND b.resource_id = :l_resource_id
AND b.product_category_id = edh.child_id AND edh.object_type = ''CATEGORY_SET'' AND edh.object_id = mtl.category_set_id
AND mtl.functional_area_id = 11 AND edh.dbi_flag = ''Y'' AND edh.parent_id = &ITEM+ENI_ITEM_VBH_CAT ';
AND b.update_period_type_id = -1
AND b.update_time_id = -1
AND b.resource_id = :l_resource_id ' ;
AND b.update_time_id=c.time_id
AND b.update_period_type_id=c.period_type_id
and b.time_id = :l_time_id
and b.period_type_id = :l_period_type_id
AND b.resource_id = :l_resource_id ';
AND b.update_time_id=c.time_id
AND b.update_period_type_id=c.period_type_id
and b.time_id = :l_prev_time_id
and b.period_type_id = :l_period_type_id
AND b.resource_id = :l_resource_id ';
AND b.update_period_type_id = -1
AND b.update_time_id = -1
AND b.resource_id = :l_resource_id
AND b.product_category_id = edh.child_id AND edh.object_type = ''CATEGORY_SET'' AND edh.object_id = mtl.category_set_id
AND mtl.functional_area_id = 11 AND edh.dbi_flag = ''Y'' AND edh.parent_id = &ITEM+ENI_ITEM_VBH_CAT ';
AND b.update_time_id= -1
AND b.update_period_type_id= -1
AND b.resource_id = :l_resource_id ';
AND b.update_time_id=c.time_id
AND b.update_period_type_id=c.period_type_id
and b.time_id = :l_time_id
and b.period_type_id = :l_period_type_id
AND b.resource_id = :l_resource_id ';
AND b.update_time_id=c.time_id
AND b.update_period_type_id=c.period_type_id
and b.time_id = :l_prev_time_id
and b.period_type_id = :l_period_type_id
AND b.resource_id = :l_resource_id ';
AND b.update_time_id= -1
AND b.update_period_type_id= -1
AND b.resource_id = :l_resource_id ';
AND b.update_time_id= -1
AND b.update_period_type_id= -1
AND b.resource_id = :l_resource_id ' ;
AND b.update_time_id=c.time_id
AND b.update_period_type_id=c.period_type_id
and b.time_id = :l_time_id
and b.period_type_id = :l_period_type_id
AND b.resource_id = :l_resource_id ' ;
AND b.update_time_id=c.time_id
AND b.update_period_type_id=c.period_type_id
and b.time_id = :l_prev_time_id
and b.period_type_id = :l_period_type_id
AND b.resource_id = :l_resource_id ' ;
AND b.update_time_id= -1
AND b.update_period_type_id= -1
AND b.resource_id = :l_resource_id ' ;
AND b.update_period_type_id = -1
AND b.update_time_id = -1
AND b.resource_id = :l_resource_id
AND b.product_category_id = edh.child_id AND edh.object_type = ''CATEGORY_SET'' AND edh.object_id = mtl.category_set_id
AND mtl.functional_area_id = 11 AND edh.dbi_flag = ''Y'' AND edh.parent_id = &ITEM+ENI_ITEM_VBH_CAT ';
AND b.update_time_id=c.time_id
AND b.update_period_type_id=c.period_type_id
and b.time_id = :l_time_id
and b.period_type_id = :l_period_type_id
AND b.resource_id = :l_resource_id
AND b.product_category_id = edh.child_id AND edh.object_type = ''CATEGORY_SET'' AND edh.object_id = mtl.category_set_id
AND mtl.functional_area_id = 11 AND edh.dbi_flag = ''Y'' AND edh.parent_id = &ITEM+ENI_ITEM_VBH_CAT ';
AND b.update_time_id=c.time_id
AND b.update_period_type_id=c.period_type_id
and b.time_id = :l_prev_time_id
and b.period_type_id = :l_period_type_id
AND b.resource_id = :l_resource_id
AND b.product_category_id = edh.child_id AND edh.object_type = ''CATEGORY_SET'' AND edh.object_id = mtl.category_set_id
AND mtl.functional_area_id = 11 AND edh.dbi_flag = ''Y'' AND edh.parent_id = &ITEM+ENI_ITEM_VBH_CAT ';
AND b.update_period_type_id = -1
AND b.update_time_id = -1
AND b.resource_id = :l_resource_id
AND b.product_category_id = edh.child_id AND edh.object_type = ''CATEGORY_SET'' AND edh.object_id = mtl.category_set_id
AND mtl.functional_area_id = 11 AND edh.dbi_flag = ''Y'' AND edh.parent_id = &ITEM+ENI_ITEM_VBH_CAT ';
AND b.update_period_type_id = -1
AND b.update_time_id = -1
AND b.resource_id = :l_resource_id ' ;
AND b.update_time_id=c.time_id
AND b.update_period_type_id=c.period_type_id
and b.time_id = :l_time_id
and b.period_type_id = :l_period_type_id
AND b.resource_id = :l_resource_id ';
AND b.update_time_id=c.time_id
AND b.update_period_type_id=c.period_type_id
and b.time_id = :l_prev_time_id
and b.period_type_id = :l_period_type_id
AND b.resource_id = :l_resource_id ';
AND b.update_period_type_id = -1
AND b.update_time_id = -1
AND b.resource_id = :l_resource_id
AND b.product_category_id = edh.child_id AND edh.object_type = ''CATEGORY_SET'' AND edh.object_id = mtl.category_set_id
AND mtl.functional_area_id = 11 AND edh.dbi_flag = ''Y'' AND edh.parent_id = &ITEM+ENI_ITEM_VBH_CAT ';
AND b.update_time_id= -1
AND b.update_period_type_id= -1
AND b.resource_id = :l_resource_id ';
AND b.update_time_id=c.time_id
AND b.update_period_type_id=c.period_type_id
and b.time_id = :l_time_id
and b.period_type_id = :l_period_type_id
AND b.resource_id = :l_resource_id ';
AND b.update_time_id=c.time_id
AND b.update_period_type_id=c.period_type_id
and b.time_id = :l_prev_time_id
and b.period_type_id = :l_period_type_id
AND b.resource_id = :l_resource_id ';
AND b.update_time_id= -1
AND b.update_period_type_id= -1
AND b.resource_id = :l_resource_id ';
AND b.update_time_id= -1
AND b.update_period_type_id= -1
AND b.resource_id = :l_resource_id ' ;
AND b.update_time_id=c.time_id
AND b.update_period_type_id=c.period_type_id
and b.time_id = :l_time_id
and b.period_type_id = :l_period_type_id
AND b.resource_id = :l_resource_id ' ;
AND b.update_time_id=c.time_id
AND b.update_period_type_id=c.period_type_id
and b.time_id = :l_prev_time_id
and b.period_type_id = :l_period_type_id
AND b.resource_id = :l_resource_id ' ;
AND b.update_time_id= -1
AND b.update_period_type_id= -1
AND b.resource_id = :l_resource_id ' ;
AND b.update_period_type_id = -1
AND b.update_time_id = -1
AND b.resource_id = :l_resource_id
AND b.product_category_id = edh.child_id AND edh.object_type = ''CATEGORY_SET'' AND edh.object_id = mtl.category_set_id
AND mtl.functional_area_id = 11 AND edh.dbi_flag = ''Y'' AND edh.parent_id = &ITEM+ENI_ITEM_VBH_CAT ';
AND b.update_time_id=c.time_id
AND b.update_period_type_id=c.period_type_id
and b.time_id = :l_time_id
and b.period_type_id = :l_period_type_id
AND b.resource_id = :l_resource_id
AND b.product_category_id = edh.child_id AND edh.object_type = ''CATEGORY_SET'' AND edh.object_id = mtl.category_set_id
AND mtl.functional_area_id = 11 AND edh.dbi_flag = ''Y'' AND edh.parent_id = &ITEM+ENI_ITEM_VBH_CAT ';
AND b.update_time_id=c.time_id
AND b.update_period_type_id=c.period_type_id
and b.time_id = :l_prev_time_id
and b.period_type_id = :l_period_type_id
AND b.resource_id = :l_resource_id
AND b.product_category_id = edh.child_id AND edh.object_type = ''CATEGORY_SET'' AND edh.object_id = mtl.category_set_id
AND mtl.functional_area_id = 11 AND edh.dbi_flag = ''Y'' AND edh.parent_id = &ITEM+ENI_ITEM_VBH_CAT ';
AND b.update_period_type_id = -1
AND b.update_time_id = -1
AND b.resource_id = :l_resource_id
AND b.product_category_id = edh.child_id AND edh.object_type = ''CATEGORY_SET'' AND edh.object_id = mtl.category_set_id
AND mtl.functional_area_id = 11 AND edh.dbi_flag = ''Y'' AND edh.parent_id = &ITEM+ENI_ITEM_VBH_CAT ';
AND b.update_period_type_id = -1
AND b.update_time_id = -1
AND b.resource_id = :l_resource_id ' ;
AND b.update_time_id=c.time_id
AND b.update_period_type_id=c.period_type_id
and b.time_id = :l_time_id
and b.period_type_id = :l_period_type_id
AND b.resource_id = :l_resource_id ';
AND b.update_time_id=c.time_id
AND b.update_period_type_id=c.period_type_id
and b.time_id = :l_prev_time_id
and b.period_type_id = :l_period_type_id
AND b.resource_id = :l_resource_id ';
AND b.update_period_type_id = -1
AND b.update_time_id = -1
AND b.resource_id = :l_resource_id
AND b.product_category_id = edh.child_id AND edh.object_type = ''CATEGORY_SET'' AND edh.object_id = mtl.category_set_id
AND mtl.functional_area_id = 11 AND edh.dbi_flag = ''Y'' AND edh.parent_id = &ITEM+ENI_ITEM_VBH_CAT ';
SELECT /*+ leading(c) */
'||l_col1_c||' BIM_SALES_GROUP,
to_char ( '||l_col2_c||' ) VIEWBYID,
'||l_col3_c||' is_resource,
sum(decode(c.report_date,&BIS_CURRENT_ASOF_DATE,leads_new,0)) leads_new,
sum(decode(c.report_date,&BIS_CURRENT_ASOF_DATE,leads_converted,0)) leads_converted,
0 leads_new_conv,
sum(decode(c.report_date,&BIS_CURRENT_ASOF_DATE,conversion_time,0)) conversion_time,
0 prev_open,
sum(decode(c.report_date,&BIS_PREVIOUS_ASOF_DATE,leads_converted,0)) prev_lead_converted,
0 prev_new_lead_converted
FROM FII_TIME_RPT_STRUCT c ,JTF_RS_RESOURCE_EXTNS_VL a, '|| l_tables_C|| '
WHERE c.calendar_id=-1
AND c.report_date in (&BIS_CURRENT_ASOF_DATE,&BIS_PREVIOUS_ASOF_DATE)
AND BITAND(c.record_type_id,:l_record_type)=c.record_type_id
'||l_where_c||'
GROUP BY '||l_col1_c||','||l_col2_c||','||l_col3_c||'
UNION ALL
/* Leads New Converted for reps*/
SELECT /*+ leading(c) */
'||l_col1_d||' BIM_SALES_GROUP,
to_char ( '||l_col2_d||' ) VIEWBYID,
'||l_col3_d||' is_resource,
0 leads_new,
0 leads_converted,
sum(leads_new_conv) leads_new_conv,
0 conversion_time,
0 prev_open,
0 prev_lead_converted,
0 prev_new_lead_converted
FROM FII_TIME_RPT_STRUCT c ,JTF_RS_RESOURCE_EXTNS_VL a, '|| l_tables_d|| '
WHERE c.calendar_id=-1
AND c.report_date = &BIS_CURRENT_ASOF_DATE
AND BITAND(c.record_type_id,1143)=c.record_type_id
'||l_where_d||'
GROUP BY '||l_col1_d||','||l_col2_d||','||l_col3_d||'
UNION ALL
/* Leads New Converted for reps*/
SELECT /*+ leading(c) */
'||l_col1_g||' BIM_SALES_GROUP,
to_char ( '||l_col2_g||' ) VIEWBYID,
'||l_col3_g||' is_resource,
0 leads_new,
0 leads_converted,
0 leads_new_conv,
0 conversion_time,
0 prev_open,
0 prev_lead_converted,
sum(leads_new_conv) prev_new_lead_converted
FROM FII_TIME_RPT_STRUCT c ,JTF_RS_RESOURCE_EXTNS_VL a, '|| l_tables_g|| '
WHERE c.calendar_id=-1
AND c.report_date = &BIS_PREVIOUS_ASOF_DATE
AND BITAND(c.record_type_id,1143)=c.record_type_id
'||l_where_g||'
GROUP BY '||l_col1_g||','||l_col2_g||','||l_col3_g||'
UNION ALL
/* prior Open for reps*/
SELECT /*+ leading(c) */
'||l_col1_f||' BIM_SALES_GROUP,
to_char ( '||l_col2_f||' ) VIEWBYID,
'||l_col3_f||' is_resource,
0 leads_new,
0 leads_converted,
0 leads_new_conv,
0 conversion_time,
sum(b.leads - (leads_closed+leads_dead+leads_converted)) prev_open,
0 prev_lead_converted,
0 prev_new_lead_converted
FROM FII_TIME_RPT_STRUCT c ,JTF_RS_RESOURCE_EXTNS_VL a, '|| l_tables_f|| '
WHERE c.calendar_id=-1
AND c.report_date = &BIS_CURRENT_EFFECTIVE_START_DATE - 1
AND BITAND(c.record_type_id,1143)=c.record_type_id
AND (b.leads-(leads_closed+leads_dead+leads_converted)) <> 0
'||l_where_f||'
GROUP BY '||l_col1_f||','||l_col2_f||','||l_col3_f;
l_query := 'SELECT BIM_SALES_GROUP VIEWBY,
VIEWBYID,
leads_converted BIM_ATTRIBUTE1,
DECODE((prev_open+leads_new),0,NULL,(leads_converted/(prev_open+leads_new))*100) BIM_ATTRIBUTE2,
DECODE(leads_new,0,NULL,(leads_new_conv/leads_new)*100) BIM_ATTRIBUTE3,
DECODE(leads_converted,0,NULL,conversion_time/leads_converted) BIM_ATTRIBUTE4,
leads_new_conv BIM_ATTRIBUTE5,
DECODE(prev_lead_converted,0,NULL,((leads_converted - prev_lead_converted)/prev_lead_converted)*100) BIM_ATTRIBUTE6,
DECODE(prev_new_lead_converted,0,NULL,((leads_new_conv - prev_new_lead_converted)/prev_new_lead_converted)*100) BIM_ATTRIBUTE7,
DECODE('||''''||l_view_by||''''||', ''ORGANIZATION+JTF_ORG_SALES_GROUP'',DECODE(is_resource,1,NULL,'||''''||l_url_str||''''||' ) ,NULL) BIM_ATTRIBUTE12,
NULL BIM_ATTRIBUTE13,
SUM(leads_converted) OVER() BIM_GRAND_TOTAL1,
DECODE(sum(open_new) over(),0,NULL,(sum(leads_converted) over()/sum(open_new) over())*100) BIM_GRAND_TOTAL2,
DECODE(sum(leads_new) over(),0,NULL,(sum(leads_new_conv) over()/sum(leads_new) over())*100) BIM_GRAND_TOTAL3,
DECODE(sum(leads_converted) over(),0,NULL,sum(conversion_time) over()/sum(leads_converted) over()) BIM_GRAND_TOTAL4,
sum(leads_new_conv) over() BIM_GRAND_TOTAL5,
DECODE(sum(prev_lead_converted) over(),0,NULL,(( sum(leads_converted - prev_lead_converted) over() )/sum(prev_lead_converted) over())*100) BIM_GRAND_TOTAL6,
DECODE(sum(prev_new_lead_converted) over(),0,NULL,((sum(leads_new_conv - prev_new_lead_converted) over())/sum(prev_new_lead_converted) over())*100) BIM_GRAND_TOTAL7
FROM
(
SELECT
BIM_SALES_GROUP,
VIEWBYID,
is_resource,
sum(leads_new) leads_new,
sum(leads_converted) leads_converted,
sum(leads_new_conv) leads_new_conv,
sum(prev_open+leads_new) open_new,
sum(conversion_time) conversion_time,
sum(prev_open) prev_open,
sum(prev_lead_converted) prev_lead_converted,
sum(prev_new_lead_converted) prev_new_lead_converted
FROM
(
SELECT /*+ leading(c) */
'||l_col1_a||' BIM_SALES_GROUP,
to_char ( '||l_col2_a||' ) VIEWBYID,
'||l_col3_a||' is_resource,
sum(decode(c.report_date,&BIS_CURRENT_ASOF_DATE,leads_new,0)) leads_new,
sum(decode(c.report_date,&BIS_CURRENT_ASOF_DATE,leads_converted,0)) leads_converted,
0 leads_new_conv,
sum(decode(c.report_date,&BIS_CURRENT_ASOF_DATE,conversion_time,0)) conversion_time,
0 prev_open,
sum(decode(c.report_date,&BIS_PREVIOUS_ASOF_DATE,leads_converted,0)) prev_lead_converted,
0 prev_new_lead_converted
FROM FII_TIME_RPT_STRUCT c , '|| l_tables_a|| '
WHERE c.calendar_id=-1
AND c.report_date in (&BIS_CURRENT_ASOF_DATE,&BIS_PREVIOUS_ASOF_DATE)
AND BITAND(c.record_type_id,:l_record_type)=c.record_type_id
'||l_where_a||'
GROUP BY '||l_col1_a||','||l_col2_a||','||l_col3_a||'
/*Leads New Converted for groups*/
UNION ALL
SELECT /*+ leading(c) */
'||l_col1_b||' BIM_SALES_GROUP,
to_char ( '||l_col2_b||' ) VIEWBYID,
'||l_col3_b||' is_resource,
0 leads_new,
0 leads_converted,
sum(leads_new_conv) leads_new_conv,
0 conversion_time,
0 prev_open,
0 prev_lead_converted,
0 prev_new_lead_converted
FROM FII_TIME_RPT_STRUCT c , '|| l_tables_b|| '
WHERE c.calendar_id=-1
AND c.report_date = &BIS_CURRENT_ASOF_DATE
AND BITAND(c.record_type_id,1143)=c.record_type_id
'||l_where_b||'
GROUP BY '||l_col1_b||','||l_col2_b||','||l_col3_b||'
/*Leads New Converted for groups*/
UNION ALL
SELECT /*+ leading(c) */
'||l_col1_h||' BIM_SALES_GROUP,
to_char ( '||l_col2_h||' ) VIEWBYID,
'||l_col3_h||' is_resource,
0 leads_new,
0 leads_converted,
0 leads_new_conv,
0 conversion_time,
0 prev_open,
0 prev_lead_converted,
sum(leads_new_conv) prev_new_lead_converted
FROM FII_TIME_RPT_STRUCT c , '|| l_tables_h|| '
WHERE c.calendar_id=-1
AND c.report_date = &BIS_PREVIOUS_ASOF_DATE
AND BITAND(c.record_type_id,1143)=c.record_type_id
'||l_where_h||'
GROUP BY '||l_col1_h||','||l_col2_h||','||l_col3_h||'
/*prior open*/
UNION ALL
select /*+ leading(c) */
'||l_col1_e||' BIM_SALES_GROUP,
to_char ( '||l_col2_e||' ) VIEWBYID,
'||l_col3_e||' is_resource,
0 leads_new,
0 leads_converted,
0 leads_new_conv,
0 conversion_time,
sum(b.leads - (leads_closed+leads_dead+leads_converted)) prev_open,
0 prev_lead_converted,
0 prev_new_lead_converted
FROM FII_TIME_RPT_STRUCT c, '|| l_tables_e|| '
WHERE c.calendar_id=-1
AND c.report_date = &BIS_CURRENT_EFFECTIVE_START_DATE - 1
AND BITAND(c.record_type_id,1143)=c.record_type_id
AND (b.leads-(leads_closed+leads_dead+leads_converted)) <> 0
'||l_where_e||'
GROUP BY '||l_col1_e||','||l_col2_e||','||l_col3_e||l_qry_sg||'
)
GROUP BY BIM_SALES_GROUP,VIEWBYID,is_resource
HAVING
sum(leads_converted) > 0
OR sum(leads_new) > 0
OR sum(prev_open)> 0
OR sum(leads_new_conv) > 0
OR sum(conversion_time) > 0
OR sum(prev_lead_converted) > 0
OR sum(prev_new_lead_converted) > 0
) ';
l_query := 'SELECT BIM_SALES_GROUP VIEWBY,
VIEWBYID,
leads_converted BIM_ATTRIBUTE1,
DECODE((prev_open+leads_new),0,NULL,(leads_converted/(prev_open+leads_new))*100) BIM_ATTRIBUTE2,
DECODE(leads_new,0,NULL,(leads_new_conv/leads_new)*100) BIM_ATTRIBUTE3,
DECODE(leads_converted,0,NULL,conversion_time/leads_converted) BIM_ATTRIBUTE4,
leads_new_conv BIM_ATTRIBUTE5,
DECODE(prev_lead_converted,0,NULL,((leads_converted - prev_lead_converted)/prev_lead_converted)*100) BIM_ATTRIBUTE6,
DECODE(prev_new_lead_converted,0,NULL,((leads_new_conv - prev_new_lead_converted)/prev_new_lead_converted)*100) BIM_ATTRIBUTE7,
DECODE('||''''||l_view_by||''''||' , ''ORGANIZATION+JTF_ORG_SALES_GROUP'',DECODE(is_resource,1,NULL,'||''''||l_url_str||''''||' ) ,NULL) BIM_ATTRIBUTE12,
NULL BIM_ATTRIBUTE13,
SUM(leads_converted) OVER() BIM_GRAND_TOTAL1,
DECODE(sum(open_new) over(),0,NULL,(sum(leads_converted) over()/sum(open_new) over())*100) BIM_GRAND_TOTAL2,
DECODE(sum(leads_new) over(),0,NULL,(sum(leads_new_conv) over()/sum(leads_new) over())*100) BIM_GRAND_TOTAL3,
DECODE(sum(leads_converted) over(),0,NULL,sum(conversion_time) over()/sum(leads_converted) over()) BIM_GRAND_TOTAL4,
sum(leads_new_conv) over() BIM_GRAND_TOTAL5,
DECODE(sum(prev_lead_converted) over(),0,NULL,(( sum(leads_converted - prev_lead_converted) over() )/sum(prev_lead_converted) over())*100) BIM_GRAND_TOTAL6,
DECODE(sum(prev_new_lead_converted) over(),0,NULL,((sum(leads_new_conv - prev_new_lead_converted) over())/sum(prev_new_lead_converted) over())*100) BIM_GRAND_TOTAL7
FROM
(
SELECT
BIM_SALES_GROUP,
VIEWBYID,
is_resource,
sum(leads_new) leads_new,
sum(leads_converted) leads_converted,
sum(leads_new_conv) leads_new_conv,
sum(prev_open+leads_new) open_new,
sum(conversion_time) conversion_time,
sum(prev_open) prev_open,
sum(prev_lead_converted) prev_lead_converted,
sum(prev_new_lead_converted) prev_new_lead_converted
FROM
(
/* Leads Converted for reps*/
SELECT /*+ leading(c) */
'||l_col1_c||' BIM_SALES_GROUP,
to_char ( '||l_col2_c||' ) VIEWBYID,
'||l_col3_c||' is_resource,
sum(decode(c.report_date,&BIS_CURRENT_ASOF_DATE,leads_new,0)) leads_new,
sum(decode(c.report_date,&BIS_CURRENT_ASOF_DATE,leads_converted,0)) leads_converted,
0 leads_new_conv,
sum(decode(c.report_date,&BIS_CURRENT_ASOF_DATE,conversion_time,0)) conversion_time,
0 prev_open,
sum(decode(c.report_date,&BIS_PREVIOUS_ASOF_DATE,leads_converted,0)) prev_lead_converted,
0 prev_new_lead_converted
FROM FII_TIME_RPT_STRUCT c , JTF_RS_RESOURCE_EXTNS_VL a, '|| l_tables_c|| '
WHERE c.calendar_id=-1
AND c.report_date in (&BIS_CURRENT_ASOF_DATE,&BIS_PREVIOUS_ASOF_DATE)
AND BITAND(c.record_type_id,:l_record_type)=c.record_type_id
'||l_where_c||'
GROUP BY '||l_col1_c||','||l_col2_c||','||l_col3_c||'
UNION ALL
/* Leads New Converted for reps*/
SELECT /*+ leading(c) */
'||l_col1_d||' BIM_SALES_GROUP,
to_char ( '||l_col2_d||' ) VIEWBYID,
'||l_col3_d||' is_resource,
0 leads_new,
0 leads_converted,
sum(leads_new_conv) leads_new_conv,
0 conversion_time,
0 prev_open,
0 prev_lead_converted,
0 prev_new_lead_converted
FROM FII_TIME_RPT_STRUCT c , JTF_RS_RESOURCE_EXTNS_VL a, '|| l_tables_d|| '
WHERE c.calendar_id=-1
AND c.report_date = &BIS_CURRENT_ASOF_DATE
AND BITAND(c.record_type_id,1143)=c.record_type_id
'||l_where_d||'
GROUP BY '||l_col1_d||','||l_col2_d||','||l_col3_d||'
UNION ALL
/* Leads New Converted for reps*/
SELECT /*+ leading(c) */
'||l_col1_g||' BIM_SALES_GROUP,
to_char ( '||l_col2_g||' ) VIEWBYID,
'||l_col3_g||' is_resource,
0 leads_new,
0 leads_converted,
0 leads_new_conv,
0 conversion_time,
0 prev_open,
0 prev_lead_converted,
sum(leads_new_conv) prev_new_lead_converted
FROM FII_TIME_RPT_STRUCT c , JTF_RS_RESOURCE_EXTNS_VL a, '|| l_tables_g|| '
WHERE c.calendar_id=-1
AND c.report_date = &BIS_PREVIOUS_ASOF_DATE
AND BITAND(c.record_type_id,1143)=c.record_type_id
'||l_where_g||'
GROUP BY '||l_col1_g||','||l_col2_g||','||l_col3_g||'
UNION ALL
/* prior Open for reps*/
SELECT /*+ leading(c) */
'||l_col1_f||' BIM_SALES_GROUP,
to_char ( '||l_col2_f||' ) VIEWBYID,
'||l_col3_f||' is_resource,
0 leads_new,
0 leads_converted,
0 leads_new_conv,
0 conversion_time,
sum(b.leads - (leads_closed+leads_dead+leads_converted)) prev_open,
0 prev_lead_converted,
0 prev_new_lead_converted
FROM FII_TIME_RPT_STRUCT c , JTF_RS_RESOURCE_EXTNS_VL a, '|| l_tables_f|| '
WHERE c.calendar_id=-1
AND c.report_date = &BIS_CURRENT_EFFECTIVE_START_DATE - 1
AND BITAND(c.record_type_id,1143)=c.record_type_id
'||l_where_f||'
GROUP BY '||l_col1_f||','||l_col2_f||','||l_col3_f||'
)
GROUP BY BIM_SALES_GROUP,VIEWBYID,is_resource
HAVING
sum(leads_converted) > 0
OR sum(leads_new) > 0
OR sum(prev_open)> 0
OR sum(leads_new_conv) > 0
OR sum(conversion_time) > 0
OR sum(prev_lead_converted) > 0
OR sum(prev_new_lead_converted) > 0
) ';
l_query := 'SELECT quality BIM_QUALITY,
age_3_below BIM_MEASURE1,
age_3_to_7 BIM_MEASURE2,
age_8_to_14 BIM_MEASURE3,
age_15_to_21 BIM_MEASURE4,
age_22_to_28 BIM_MEASURE5,
age_29_to_35 BIM_MEASURE6,
age_36_to_42 BIM_MEASURE7,
age_42_to_above BIM_MEASURE8,
(age_3_below+age_3_to_7+age_8_to_14+age_15_to_21+age_22_to_28+age_29_to_35+
age_36_to_42+age_42_to_above) BIM_MEASURE9,
SUM(age_3_below) over() BIM_GRAND_TOTAL1,
SUM(age_3_to_7) over() BIM_GRAND_TOTAL2,
SUM(age_8_to_14) over() BIM_GRAND_TOTAL3,
SUM(age_15_to_21) over() BIM_GRAND_TOTAL4,
SUM(age_22_to_28) over() BIM_GRAND_TOTAL5,
SUM(age_29_to_35) over() BIM_GRAND_TOTAL6,
SUM(age_36_to_42) over() BIM_GRAND_TOTAL7,
SUM(age_42_to_above) over() BIM_GRAND_TOTAL8,
SUM(age_3_below+age_3_to_7+age_8_to_14+age_15_to_21+age_22_to_28+age_29_to_35+
age_36_to_42+age_42_to_above) over() BIM_GRAND_TOTAL9
FROM(select quality,age_3_below,age_3_to_7,age_8_to_14,age_15_to_21,
age_22_to_28,age_29_to_35,age_36_to_42,age_42_to_above
from(select decode(b.rank_code,''Z'',''Other'',a.meaning) quality,b.age_3_below,b.age_3_to_7,b.age_8_to_14,
b.age_15_to_21,b.age_22_to_28,b.age_29_to_35,b.age_36_to_42,
b.age_42_to_above
FROM BIM_I_LD_AGE_QU_MV b,
AS_SALES_LEAD_RANKS_TL a
WHERE b.group_id IN ( &ORGANIZATION+JTF_ORG_SALES_GROUP )
AND a.rank_id(+) = b.rank_id
AND a.language(+)=USERENV(''LANG'')
order by rank_code
)
)
WHERE age_3_below > 0
AND age_3_to_7 > 0
AND age_8_to_14 > 0
AND age_15_to_21 > 0
AND age_22_to_28 > 0
AND age_29_to_35 > 0
AND age_36_to_42 > 0
AND age_42_to_above > 0
&ORDER_BY_CLAUSE
';
l_query := 'SELECT quality BIM_QUALITY,
age_3_below BIM_MEASURE1,
age_3_to_7 BIM_MEASURE2,
age_8_to_14 BIM_MEASURE3,
age_15_to_21 BIM_MEASURE4,
age_22_to_28 BIM_MEASURE5,
age_29_to_35 BIM_MEASURE6,
age_36_to_42 BIM_MEASURE7,
age_42_to_above BIM_MEASURE8,
(age_3_below+age_3_to_7+age_8_to_14+age_15_to_21+age_22_to_28+age_29_to_35+
age_36_to_42+age_42_to_above) BIM_MEASURE9,
SUM(age_3_below) over() BIM_GRAND_TOTAL1,
SUM(age_3_to_7) over() BIM_GRAND_TOTAL2,
SUM(age_8_to_14) over() BIM_GRAND_TOTAL3,
SUM(age_15_to_21) over() BIM_GRAND_TOTAL4,
SUM(age_22_to_28) over() BIM_GRAND_TOTAL5,
SUM(age_29_to_35) over() BIM_GRAND_TOTAL6,
SUM(age_36_to_42) over() BIM_GRAND_TOTAL7,
SUM(age_42_to_above) over() BIM_GRAND_TOTAL8,
SUM(age_3_below+age_3_to_7+age_8_to_14+age_15_to_21+age_22_to_28+age_29_to_35+
age_36_to_42+age_42_to_above) over() BIM_GRAND_TOTAL9
FROM(select quality,age_3_below,age_3_to_7,age_8_to_14,age_15_to_21,
age_22_to_28,age_29_to_35,age_36_to_42,age_42_to_above
from(select decode(b.rank_code,''Z'',''Other'',a.meaning) quality,b.age_3_below,b.age_3_to_7,b.age_8_to_14,
b.age_15_to_21,b.age_22_to_28,b.age_29_to_35,b.age_36_to_42,
b.age_42_to_above
FROM BIM_I_LP_AGE_QU_MV b,
AS_SALES_LEAD_RANKS_TL a
WHERE b.group_id IN ( &ORGANIZATION+JTF_ORG_SALES_GROUP )
AND a.rank_id(+) = b.rank_id
AND a.language(+)=USERENV(''LANG'')
AND b.product_category_id = &ITEM+ENI_ITEM_VBH_CAT
AND b.umark = 1
order by rank_code
)
)
WHERE age_3_below > 0
AND age_3_to_7 > 0
AND age_8_to_14 > 0
AND age_15_to_21 > 0
AND age_22_to_28 > 0
AND age_29_to_35 > 0
AND age_36_to_42 > 0
AND age_42_to_above > 0
&ORDER_BY_CLAUSE';
l_query := 'SELECT
NULL VIEWBY,
NULL VIEWBYID,
NULL BIM_MEASURE1,
NULL BIM_MEASURE2,
NULL BIM_MEASURE3,
NULL BIM_MEASURE4,
NULL BIM_MEASURE5,
NULL BIM_MEASURE6,
NULL BIM_MEASURE8,
NULL BIM_MEASURE7,
NULL BIM_MEASURE9,
NULL BIM_URL1,
NULL BIM_URL2,
NULL BIM_URL3,
NULL BIM_URL4,
NULL BIM_URL5,
NULL BIM_URL6,
NULL BIM_URL7,
NULL BIM_GRAND_TOTAL1,
NULL BIM_GRAND_TOTAL2,
NULL BIM_GRAND_TOTAL3,
NULL BIM_GRAND_TOTAL4,
NULL BIM_GRAND_TOTAL5,
NULL BIM_GRAND_TOTAL6,
NULL bim_GRAND_TOTAL7,
NULL bim_GRAND_TOTAL8,
NULL bim_GRAND_TOTAL9
FROM dual';
AND b.update_time_id= -1
AND b.update_period_type_id= -1
AND b.resource_id = :l_resource_id ';
AND b.update_time_id= -1
AND b.update_period_type_id= -1
AND b.resource_id <> :l_resource_id';
AND b.update_time_id= -1
AND b.update_period_type_id= -1
AND b.resource_id = :l_resource_id ' ;
AND b.update_period_type_id = -1
AND b.update_time_id = -1
AND b.resource_id = :l_resource_id
AND b.product_category_id = edh.child_id AND edh.object_type = ''CATEGORY_SET'' AND edh.object_id = mtl.category_set_id AND mtl.functional_area_id = 11 AND edh.dbi_flag = ''Y'' AND edh.parent_id = &ITEM+ENI_ITEM_VBH_CAT ';
AND b.update_period_type_id = -1
AND b.update_time_id = -1
AND b.resource_id <> :l_resource_id ';
AND b.update_period_type_id = -1
AND b.update_time_id = -1
AND b.resource_id = :l_resource_id ' ;
/* If Sales Rep is not selected */
IF (l_resource_id is null) THEN
l_query := '
SELECT BIM_SALES_GROUP VIEWBY,
VIEWBYID,
RANK_A BIM_ATTRIBUTE1,
RANK_B BIM_ATTRIBUTE2,
RANK_C BIM_ATTRIBUTE3,
RANK_D BIM_ATTRIBUTE4,
RANK_Z BIM_ATTRIBUTE5,
RANK_TOTAL BIM_ATTRIBUTE6,
decode(SUM(RANK_A + RANK_B + RANK_C + RANK_D + RANK_Z) OVER(),0,0,((RANK_TOTAL * 100)/ SUM(RANK_A + RANK_B + RANK_C + RANK_D + RANK_Z) OVER())) BIM_ATTRIBUTE7,
LEADS_QUALIFIED BIM_ATTRIBUTE8,
RANK_A BIM_ATTRIBUTE9,
LEADS_QUALIFIED BIM_ATTRIBUTE13,
NULL BIM_ATTRIBUTE14,
DECODE(leaf_node_flag,''Y'',NULL,'||''''||l_url_str||''''||' ) BIM_ATTRIBUTE15,
(RANK_TOTAL - (RANK_A + RANK_B)) BIM_ATTRIBUTE16,
decode(VIEWBYID,-1,null,decode(RANK_A,0,NULL,'||''''||l_url_str1||''''||'||'||''''||l_Metric_a||''''||'||'||''''||l_rpt_name||''''||'||VIEWBYID'||'||'||''''||l_context_info||')) BIM_URL1,
decode(VIEWBYID,-1,null,decode(RANK_B,0,NULL,'||''''||l_url_str2||''''||'||'||''''||l_Metric_b||''''||'||'||''''||l_rpt_name||''''||'||VIEWBYID'||'||'||''''||l_context_info||')) BIM_URL2,
decode(VIEWBYID,-1,null,decode(RANK_C,0,NULL,'||''''||l_url_str3||''''||'||'||''''||l_Metric_c||''''||'||'||''''||l_rpt_name||''''||'||VIEWBYID'||'||'||''''||l_context_info||')) BIM_URL3,
decode(VIEWBYID,-1,null,decode(RANK_D,0,NULL,'||''''||l_url_str4||''''||'||'||''''||l_Metric_d||''''||'||'||''''||l_rpt_name||''''||'||VIEWBYID'||'||'||''''||l_context_info||')) BIM_URL4,
decode(VIEWBYID,-1,null,decode(RANK_Z,0,NULL,'||''''||l_url_str5||''''||'||'||''''||l_Metric_e||''''||'||'||''''||l_rpt_name||''''||'||VIEWBYID'||'||'||''''||l_context_info||')) BIM_URL5,
SUM(RANK_A) OVER() BIM_GRAND_TOTAL1,
SUM(RANK_B) OVER() BIM_GRAND_TOTAL2,
SUM(RANK_C) OVER() BIM_GRAND_TOTAL3,
SUM(RANK_D) OVER() BIM_GRAND_TOTAL4,
SUM(RANK_Z) OVER() BIM_GRAND_TOTAL5,
SUM(RANK_TOTAL) OVER() BIM_GRAND_TOTAL6,
decode(SUM(RANK_TOTAL) OVER(),0,0,(SUM(RANK_TOTAL) OVER()) * 100/(SUM(RANK_TOTAL) OVER())) BIM_GRAND_TOTAL7,
SUM(LEADS_QUALIFIED) OVER() BIM_GRAND_TOTAL8,
SUM(RANK_A) OVER() BIM_GRAND_TOTAL9,
SUM(LEADS_QUALIFIED) OVER() BIM_GRAND_TOTAL10
FROM
(
/*Others for sales group*/
select /*+ leading(c) */
p.value BIM_SALES_GROUP,
p.parent_id VIEWBYID,
p.leaf_node_flag leaf_node_flag,
sum(rank_a) rank_a,
sum(rank_b) rank_b,
sum(rank_c) rank_c,
sum(rank_d) rank_d,
sum(rank_z) rank_z,
sum(rank_a + rank_b + rank_c + rank_d + rank_z) rank_total,
sum(leads_qualified) leads_qualified
FROM FII_TIME_RPT_STRUCT c,( SELECT e.parent_id parent_id ,e.value value,e.leaf_node_flag leaf_node_flag
FROM eni_item_vbh_nodes_v e
WHERE e.top_node_flag=''Y''
AND e.child_id = e.parent_id) p
,eni_denorm_hierarchies edh
,mtl_default_category_sets d
, BIM_I_LP_GEN_SG_MV b
WHERE
b.group_id = &ORGANIZATION+JTF_ORG_SALES_GROUP
AND b.product_category_id = edh.child_id
AND edh.object_type = ''CATEGORY_SET''
AND edh.object_id = d.category_set_id
AND d.functional_area_id = 11
AND edh.dbi_flag = ''Y''
AND edh.parent_id = p.parent_id
AND c.calendar_id=-1
AND c.report_date = &BIS_CURRENT_ASOF_DATE
AND BITAND(c.record_type_id,:l_record_type)=c.record_type_id
AND b.time_id=c.time_id
AND b.period_type_id=c.period_type_id
AND b.update_period_type_id = -1
AND b.update_time_id = -1
AND b.resource_id =:l_resource_id
GROUP BY p.value,p.parent_id,p.leaf_node_flag
HAVING SUM(RANK_A) > 0
OR SUM(RANK_B) > 0
OR SUM(RANK_C) > 0
OR SUM(RANK_D) > 0
OR SUM(RANK_Z) > 0
) &ORDER_BY_CLAUSE';
/* If Sales Rep is selected */
l_query := '
SELECT BIM_SALES_GROUP VIEWBY,
VIEWBYID,
RANK_A BIM_ATTRIBUTE1,
RANK_B BIM_ATTRIBUTE2,
RANK_C BIM_ATTRIBUTE3,
RANK_D BIM_ATTRIBUTE4,
RANK_Z BIM_ATTRIBUTE5,
RANK_TOTAL BIM_ATTRIBUTE6,
decode(SUM(RANK_A + RANK_B + RANK_C + RANK_D + RANK_Z) OVER(),0,0,((RANK_TOTAL * 100)/ SUM(RANK_A + RANK_B + RANK_C + RANK_D + RANK_Z) OVER())) BIM_ATTRIBUTE7,
LEADS_QUALIFIED BIM_ATTRIBUTE8,
RANK_A BIM_ATTRIBUTE9,
LEADS_QUALIFIED BIM_ATTRIBUTE13,
NULL BIM_ATTRIBUTE14,
DECODE(leaf_node_flag,''Y'',NULL,'||''''||l_url_str||''''||' ) BIM_ATTRIBUTE15,
(RANK_TOTAL - (RANK_A + RANK_B)) BIM_ATTRIBUTE16,
decode(VIEWBYID,-1,null,decode(RANK_A,0,NULL,'||''''||l_url_str1||''''||'||'||''''||l_Metric_a||''''||'||'||''''||l_rpt_name||''''||'||VIEWBYID'||'||'||''''||l_context_info||')) BIM_URL1,
decode(VIEWBYID,-1,null,decode(RANK_B,0,NULL,'||''''||l_url_str2||''''||'||'||''''||l_Metric_b||''''||'||'||''''||l_rpt_name||''''||'||VIEWBYID'||'||'||''''||l_context_info||')) BIM_URL2,
decode(VIEWBYID,-1,null,decode(RANK_C,0,NULL,'||''''||l_url_str3||''''||'||'||''''||l_Metric_c||''''||'||'||''''||l_rpt_name||''''||'||VIEWBYID'||'||'||''''||l_context_info||')) BIM_URL3,
decode(VIEWBYID,-1,null,decode(RANK_D,0,NULL,'||''''||l_url_str4||''''||'||'||''''||l_Metric_d||''''||'||'||''''||l_rpt_name||''''||'||VIEWBYID'||'||'||''''||l_context_info||')) BIM_URL4,
decode(VIEWBYID,-1,null,decode(RANK_Z,0,NULL,'||''''||l_url_str5||''''||'||'||''''||l_Metric_e||''''||'||'||''''||l_rpt_name||''''||'||VIEWBYID'||'||'||''''||l_context_info||')) BIM_URL5,
SUM(RANK_A) OVER() BIM_GRAND_TOTAL1,
SUM(RANK_B) OVER() BIM_GRAND_TOTAL2,
SUM(RANK_C) OVER() BIM_GRAND_TOTAL3,
SUM(RANK_D) OVER() BIM_GRAND_TOTAL4,
SUM(RANK_Z) OVER() BIM_GRAND_TOTAL5,
SUM(RANK_TOTAL) OVER() BIM_GRAND_TOTAL6,
decode(SUM(RANK_TOTAL) OVER(),0,0,(SUM(RANK_TOTAL) OVER()) * 100/(SUM(RANK_TOTAL) OVER())) BIM_GRAND_TOTAL7,
SUM(LEADS_QUALIFIED) OVER() BIM_GRAND_TOTAL8,
SUM(RANK_A) OVER() BIM_GRAND_TOTAL9,
SUM(LEADS_QUALIFIED) OVER() BIM_GRAND_TOTAL10
FROM
(
/*Others for sales group*/
select /*+ leading(c) */
p.value BIM_SALES_GROUP,
p.parent_id VIEWBYID,
p.leaf_node_flag leaf_node_flag,
sum(rank_a) rank_a,
sum(rank_b) rank_b,
sum(rank_c) rank_c,
sum(rank_d) rank_d,
sum(rank_z) rank_z,
sum(rank_a + rank_b + rank_c + rank_d + rank_z) rank_total,
sum(leads_qualified) leads_qualified
FROM FII_TIME_RPT_STRUCT c,( SELECT e.parent_id parent_id ,e.value value,e.leaf_node_flag leaf_node_flag
FROM eni_item_vbh_nodes_v e
WHERE e.top_node_flag=''Y''
AND e.child_id = e.parent_id) p
,eni_denorm_hierarchies edh
,mtl_default_category_sets d, BIM_I_LP_GEN_SG_MV b
WHERE
b.group_id = :l_group_id
AND b.product_category_id = edh.child_id
AND edh.object_type = ''CATEGORY_SET''
AND edh.object_id = d.category_set_id
AND d.functional_area_id = 11
AND edh.dbi_flag = ''Y''
AND edh.parent_id = p.parent_id
AND c.calendar_id=-1
AND c.report_date = &BIS_CURRENT_ASOF_DATE
AND BITAND(c.record_type_id,:l_record_type)=c.record_type_id
AND b.time_id=c.time_id
AND b.period_type_id=c.period_type_id
AND b.update_period_type_id = -1
AND b.update_time_id = -1
AND b.resource_id = :l_resource_id
GROUP BY p.value,p.parent_id,p.leaf_node_flag
HAVING SUM(RANK_A) > 0
OR SUM(RANK_B) > 0
OR SUM(RANK_C) > 0
OR SUM(RANK_D) > 0
OR SUM(RANK_Z) > 0
) &ORDER_BY_CLAUSE';
/* If Sales Rep is not selected */
IF (l_resource_id is null) THEN
l_query := '
SELECT BIM_SALES_GROUP VIEWBY,
VIEWBYID,
RANK_A BIM_ATTRIBUTE1,
RANK_B BIM_ATTRIBUTE2,
RANK_C BIM_ATTRIBUTE3,
RANK_D BIM_ATTRIBUTE4,
RANK_Z BIM_ATTRIBUTE5,
RANK_TOTAL BIM_ATTRIBUTE6,
decode(SUM(RANK_A + RANK_B + RANK_C + RANK_D + RANK_Z) OVER(),0,0,((RANK_TOTAL * 100)/ SUM(RANK_A + RANK_B + RANK_C + RANK_D + RANK_Z) OVER())) BIM_ATTRIBUTE7,
LEADS_QUALIFIED BIM_ATTRIBUTE8,
RANK_A BIM_ATTRIBUTE9,
LEADS_QUALIFIED BIM_ATTRIBUTE13,
NULL BIM_ATTRIBUTE14,
DECODE(leaf_node_flag,''Y'',NULL,'||''''||l_url_str||''''||' ) BIM_ATTRIBUTE15,
(RANK_TOTAL - (RANK_A + RANK_B)) BIM_ATTRIBUTE16,
CASE WHEN VIEWBYID = -1 THEN null WHEN dir_flag = 1 THEN null WHEN RANK_A = 0 THEN NULL ELSE '||''''||l_url_str1||''''||'||'||''''||l_Metric_a||''''||'||'||''''||l_rpt_name||''''||'||VIEWBYID'||'||'||''''||l_context_info||' END BIM_URL1,
CASE WHEN VIEWBYID = -1 THEN null WHEN dir_flag = 1 THEN null WHEN RANK_B = 0 THEN NULL ELSE '||''''||l_url_str2||''''||'||'||''''||l_Metric_b||''''||'||'||''''||l_rpt_name||''''||'||VIEWBYID'||'||'||''''||l_context_info||' END BIM_URL2,
CASE WHEN VIEWBYID = -1 THEN null WHEN dir_flag = 1 THEN null WHEN RANK_C = 0 THEN NULL ELSE '||''''||l_url_str3||''''||'||'||''''||l_Metric_c||''''||'||'||''''||l_rpt_name||''''||'||VIEWBYID'||'||'||''''||l_context_info||' END BIM_URL3,
CASE WHEN VIEWBYID = -1 THEN null WHEN dir_flag = 1 THEN null WHEN RANK_D = 0 THEN NULL ELSE '||''''||l_url_str4||''''||'||'||''''||l_Metric_d||''''||'||'||''''||l_rpt_name||''''||'||VIEWBYID'||'||'||''''||l_context_info||' END BIM_URL4,
CASE WHEN VIEWBYID = -1 THEN null WHEN dir_flag = 1 THEN null WHEN RANK_Z = 0 THEN NULL ELSE '||''''||l_url_str5||''''||'||'||''''||l_Metric_e||''''||'||'||''''||l_rpt_name||''''||'||VIEWBYID'||'||'||''''||l_context_info||' END BIM_URL5,
SUM(RANK_A) OVER() BIM_GRAND_TOTAL1,SUM(RANK_B) OVER() BIM_GRAND_TOTAL2,SUM(RANK_C) OVER() BIM_GRAND_TOTAL3,SUM(RANK_D) OVER() BIM_GRAND_TOTAL4,
SUM(RANK_Z) OVER() BIM_GRAND_TOTAL5,SUM(RANK_TOTAL) OVER() BIM_GRAND_TOTAL6,
decode(SUM(RANK_TOTAL) OVER(),0,0,(SUM(RANK_TOTAL) OVER()) * 100/(SUM(RANK_TOTAL) OVER())) BIM_GRAND_TOTAL7,
SUM(LEADS_QUALIFIED) OVER() BIM_GRAND_TOTAL8,SUM(RANK_A) OVER() BIM_GRAND_TOTAL9,SUM(LEADS_QUALIFIED) OVER() BIM_GRAND_TOTAL10
FROM
(
select /*+ leading(c) */
p.value BIM_SALES_GROUP,
p.id VIEWBYID,p.leaf_node_flag leaf_node_flag,
0 dir_flag,sum(rank_a) rank_a,sum(rank_b) rank_b,
sum(rank_c) rank_c,sum(rank_d) rank_d,sum(rank_z) rank_z,
sum(rank_a + rank_b + rank_c + rank_d + rank_z) rank_total,
sum(leads_qualified) leads_qualified
FROM FII_TIME_RPT_STRUCT c,BIM_I_LP_GEN_SG_MV b,eni_denorm_hierarchies edh
,mtl_default_category_sets mdc
,(select e.id,e.value,leaf_node_flag
from eni_item_vbh_nodes_v e
where
e.parent_id =&ITEM+ENI_ITEM_VBH_CAT
AND e.id = e.child_id
AND((e.leaf_node_flag=''N'' AND e.parent_id<>e.id) OR e.leaf_node_flag=''Y'')
) p
WHERE
b.group_id = &ORGANIZATION+JTF_ORG_SALES_GROUP
AND b.product_category_id = edh.child_id
AND edh.object_type = ''CATEGORY_SET''
AND edh.object_id = mdc.category_set_id
AND mdc.functional_area_id = 11
AND edh.dbi_flag = ''Y''
AND edh.parent_id = p.id
AND c.calendar_id=-1
AND c.report_date = &BIS_CURRENT_ASOF_DATE
AND BITAND(c.record_type_id,:l_record_type)=c.record_type_id
AND b.time_id=c.time_id
AND b.period_type_id=c.period_type_id
AND b.resource_id = :l_resource_id
AND b.update_period_type_id = -1
AND b.update_time_id = -1
GROUP BY p.value,p.id,p.leaf_node_flag
UNION ALL
select /*+ leading(c) */
bim_pmv_dbi_utl_pkg.get_lookup_value('||''''||'DASS'||''''||')'||' BIM_SALES_GROUP,
p.id VIEWBYID,
''Y'' leaf_node_flag,
1 dir_flag,
sum(rank_a) rank_a,
sum(rank_b) rank_b,
sum(rank_c) rank_c,
sum(rank_d) rank_d,
sum(rank_z) rank_z,
sum(rank_a + rank_b + rank_c + rank_d + rank_z) rank_total,
sum(leads_qualified) leads_qualified
FROM FII_TIME_RPT_STRUCT c,BIM_I_LP_GEN_SG_MV b,(select e.id id,e.value value
from eni_item_vbh_nodes_v e
where e.parent_id = &ITEM+ENI_ITEM_VBH_CAT
AND e.parent_id = e.child_id
AND leaf_node_flag <> ''Y''
) p
WHERE
b.group_id = &ORGANIZATION+JTF_ORG_SALES_GROUP
AND p.id = b.product_category_id
AND c.calendar_id=-1
AND c.report_date = &BIS_CURRENT_ASOF_DATE
AND BITAND(c.record_type_id,:l_record_type)=c.record_type_id
AND b.time_id=c.time_id
AND b.period_type_id=c.period_type_id
AND b.update_period_type_id = -1
AND b.update_time_id = -1
AND b.resource_id = :l_resource_id
AND b.item_id = ''-1''
GROUP BY p.value,p.id
) WHERE RANK_A > 0 OR RANK_B > 0 OR RANK_C > 0 OR RANK_D > 0 OR RANK_Z > 0 &ORDER_BY_CLAUSE';
/* If Sales Rep is selected */
l_query := '
SELECT BIM_SALES_GROUP VIEWBY,
VIEWBYID,RANK_A BIM_ATTRIBUTE1,RANK_B BIM_ATTRIBUTE2,RANK_C BIM_ATTRIBUTE3,
RANK_D BIM_ATTRIBUTE4,RANK_Z BIM_ATTRIBUTE5,RANK_TOTAL BIM_ATTRIBUTE6,
decode(SUM(RANK_A + RANK_B + RANK_C + RANK_D + RANK_Z) OVER(),0,0,((RANK_TOTAL * 100)/ SUM(RANK_A + RANK_B + RANK_C + RANK_D + RANK_Z) OVER())) BIM_ATTRIBUTE7,
LEADS_QUALIFIED BIM_ATTRIBUTE8,RANK_A BIM_ATTRIBUTE9,LEADS_QUALIFIED BIM_ATTRIBUTE13,NULL BIM_ATTRIBUTE14,
DECODE(leaf_node_flag,''Y'',NULL,'||''''||l_url_str||''''||' ) BIM_ATTRIBUTE15,
(RANK_TOTAL - (RANK_A + RANK_B)) BIM_ATTRIBUTE16,
CASE WHEN VIEWBYID = -1 THEN null WHEN dir_flag = 1 THEN null WHEN RANK_A = 0 THEN NULL ELSE '||''''||l_url_str1||''''||'||'||''''||l_Metric_a||''''||'||'||''''||l_rpt_name||''''||'||VIEWBYID'||'||'||''''||l_context_info||' END BIM_URL1,
CASE WHEN VIEWBYID = -1 THEN null WHEN dir_flag = 1 THEN null WHEN RANK_B = 0 THEN NULL ELSE '||''''||l_url_str2||''''||'||'||''''||l_Metric_b||''''||'||'||''''||l_rpt_name||''''||'||VIEWBYID'||'||'||''''||l_context_info||' END BIM_URL2,
CASE WHEN VIEWBYID = -1 THEN null WHEN dir_flag = 1 THEN null WHEN RANK_C = 0 THEN NULL ELSE'||''''||l_url_str3||''''||'||'||''''||l_Metric_c||''''||'||'||''''||l_rpt_name||''''||'||VIEWBYID'||'||'||''''||l_context_info||' END BIM_URL3,
CASE WHEN VIEWBYID = -1 THEN null WHEN dir_flag = 1 THEN null WHEN RANK_D = 0 THEN NULL ELSE '||''''||l_url_str4||''''||'||'||''''||l_Metric_d||''''||'||'||''''||l_rpt_name||''''||'||VIEWBYID'||'||'||''''||l_context_info||' END BIM_URL4,
CASE WHEN VIEWBYID = -1 THEN null WHEN dir_flag = 1 THEN null WHEN RANK_Z = 0 THEN NULL ELSE '||''''||l_url_str5||''''||'||'||''''||l_Metric_e||''''||'||'||''''||l_rpt_name||''''||'||VIEWBYID'||'||'||''''||l_context_info||' END BIM_URL5,
SUM(RANK_A) OVER() BIM_GRAND_TOTAL1,
SUM(RANK_B) OVER() BIM_GRAND_TOTAL2,
SUM(RANK_C) OVER() BIM_GRAND_TOTAL3,
SUM(RANK_D) OVER() BIM_GRAND_TOTAL4,
SUM(RANK_Z) OVER() BIM_GRAND_TOTAL5,
SUM(RANK_TOTAL) OVER() BIM_GRAND_TOTAL6,
decode(SUM(RANK_TOTAL) OVER(),0,0,(SUM(RANK_TOTAL) OVER()) * 100/(SUM(RANK_TOTAL) OVER())) BIM_GRAND_TOTAL7,
SUM(LEADS_QUALIFIED) OVER() BIM_GRAND_TOTAL8,
SUM(RANK_A) OVER() BIM_GRAND_TOTAL9,
SUM(LEADS_QUALIFIED) OVER() BIM_GRAND_TOTAL10
FROM
(
select /*+ leading(c) */
p.value BIM_SALES_GROUP,p.id VIEWBYID,
p.leaf_node_flag leaf_node_flag,0 dir_flag,sum(rank_a) rank_a,sum(rank_b) rank_b,sum(rank_c) rank_c,
sum(rank_d) rank_d,sum(rank_z) rank_z,sum(rank_a + rank_b + rank_c + rank_d + rank_z) rank_total,
sum(leads_qualified) leads_qualified
FROM FII_TIME_RPT_STRUCT c,BIM_I_LP_GEN_SG_MV b,eni_denorm_hierarchies edh
,mtl_default_category_sets mdc
,(select e.id,e.value,leaf_node_flag
from eni_item_vbh_nodes_v e
where
e.parent_id =&ITEM+ENI_ITEM_VBH_CAT
AND e.id = e.child_id
AND((e.leaf_node_flag=''N'' AND e.parent_id<>e.id) OR e.leaf_node_flag=''Y'')
) p
WHERE
b.group_id = :l_group_id
AND b.product_category_id = edh.child_id
AND edh.object_type = ''CATEGORY_SET''
AND edh.object_id = mdc.category_set_id
AND mdc.functional_area_id = 11
AND edh.dbi_flag = ''Y''
AND edh.parent_id = p.id
AND c.calendar_id=-1
AND c.report_date = &BIS_CURRENT_ASOF_DATE
AND BITAND(c.record_type_id,:l_record_type)=c.record_type_id
AND b.time_id=c.time_id
AND b.period_type_id=c.period_type_id
AND b.resource_id = :l_resource_id
AND b.update_period_type_id = -1
AND b.update_time_id = -1
GROUP BY p.value,p.id,p.leaf_node_flag
UNION ALL
select /*+ leading(c) */
bim_pmv_dbi_utl_pkg.get_lookup_value('||''''||'DASS'||''''||')'||' BIM_SALES_GROUP,
p.id VIEWBYID,''Y'' leaf_node_flag,1 dir_flag,sum(rank_a) rank_a,sum(rank_b) rank_b,
sum(rank_c) rank_c,sum(rank_d) rank_d,sum(rank_z) rank_z,sum(rank_a + rank_b + rank_c + rank_d + rank_z) rank_total,
sum(leads_qualified) leads_qualified
FROM FII_TIME_RPT_STRUCT c,BIM_I_LP_GEN_SG_MV b ,(select e.id id,e.value value
from eni_item_vbh_nodes_v e
where e.parent_id = &ITEM+ENI_ITEM_VBH_CAT
AND e.parent_id = e.child_id
AND leaf_node_flag <> ''Y''
) p
WHERE
b.group_id = :l_group_id
AND p.id = b.product_category_id
AND c.calendar_id=-1
AND c.report_date = &BIS_CURRENT_ASOF_DATE
AND BITAND(c.record_type_id,:l_record_type)=c.record_type_id
AND b.time_id=c.time_id
AND b.period_type_id=c.period_type_id
AND b.update_period_type_id = -1
AND b.update_time_id = -1
AND b.resource_id = :l_resource_id
AND b.item_id = ''-1''
GROUP BY p.value,p.id
) WHERE RANK_A > 0 OR RANK_B > 0 OR RANK_C > 0 OR RANK_D > 0 OR RANK_Z > 0 &ORDER_BY_CLAUSE';
AND b.update_time_id= -1
AND b.update_period_type_id= -1
AND b.resource_id = :l_resource_id ';
AND b.update_time_id= -1
AND b.update_period_type_id= -1
AND b.resource_id = :l_resource_id ' ;
AND b.update_period_type_id = -1
AND b.update_time_id = -1
AND b.resource_id = :l_resource_id
AND b.product_category_id = edh.child_id AND edh.object_type = ''CATEGORY_SET'' AND edh.object_id = mtl.category_set_id
AND mtl.functional_area_id = 11 AND edh.dbi_flag = ''Y'' AND edh.parent_id = &ITEM+ENI_ITEM_VBH_CAT ';
AND b.update_period_type_id = -1
AND b.resource_id = :l_resource_id
AND b.update_time_id = -1
AND b.product_category_id = edh.child_id AND edh.object_type = ''CATEGORY_SET'' AND edh.object_id = mtl.category_set_id
AND mtl.functional_area_id = 11 AND edh.dbi_flag = ''Y'' AND edh.parent_id = &ITEM+ENI_ITEM_VBH_CAT ';
AND b.update_time_id= -1
AND b.update_period_type_id= -1
AND b.resource_id = :l_resource_id ';
AND b.update_time_id= -1
AND b.update_period_type_id= -1
AND b.resource_id = :l_resource_id ';
AND b.update_period_type_id = -1
AND b.update_time_id = -1
AND b.resource_id = :l_resource_id
AND b.product_category_id = edh.child_id
AND edh.object_type = ''CATEGORY_SET'' AND edh.object_id = mtl.category_set_id
AND mtl.functional_area_id = 11 AND edh.dbi_flag = ''Y'' AND edh.parent_id = &ITEM+ENI_ITEM_VBH_CAT ';
AND b.update_period_type_id = -1
AND b.resource_id = :l_resource_id
AND b.update_time_id = -1
AND b.product_category_id = edh.child_id AND edh.object_type = ''CATEGORY_SET'' AND edh.object_id = mtl.category_set_id
AND mtl.functional_area_id = 11 AND edh.dbi_flag = ''Y'' AND edh.parent_id = &ITEM+ENI_ITEM_VBH_CAT ';
AND b.update_time_id= -1
AND b.update_period_type_id= -1
AND b.resource_id = :l_resource_id ';
AND b.update_time_id= -1
AND b.update_period_type_id= -1
AND b.resource_id = :l_resource_id ' ;
AND b.update_period_type_id = -1
AND b.update_time_id = -1
AND b.resource_id = :l_resource_id
AND b.product_category_id = edh.child_id AND edh.object_type = ''CATEGORY_SET'' AND edh.object_id = mtl.category_set_id
AND mtl.functional_area_id = 11 AND edh.dbi_flag = ''Y'' AND edh.parent_id = &ITEM+ENI_ITEM_VBH_CAT ';
AND b.update_period_type_id = -1
AND b.resource_id = :l_resource_id
AND b.update_time_id = -1
AND b.product_category_id = edh.child_id AND edh.object_type = ''CATEGORY_SET'' AND edh.object_id = mtl.category_set_id
AND mtl.functional_area_id = 11 AND edh.dbi_flag = ''Y'' AND edh.parent_id = &ITEM+ENI_ITEM_VBH_CAT ';
AND b.update_time_id= -1
AND b.update_period_type_id= -1
AND b.resource_id = :l_resource_id ';
AND b.update_time_id= -1
AND b.update_period_type_id= -1
AND b.resource_id = :l_resource_id ' ;
AND b.update_period_type_id = -1
AND b.update_time_id = -1
AND b.resource_id = :l_resource_id
AND b.product_category_id = edh.child_id AND edh.object_type = ''CATEGORY_SET'' AND edh.object_id = mtl.category_set_id
AND mtl.functional_area_id = 11 AND edh.dbi_flag = ''Y'' AND edh.parent_id = &ITEM+ENI_ITEM_VBH_CAT ';
AND b.update_period_type_id = -1
AND b.resource_id = :l_resource_id
AND b.update_time_id = -1
AND b.product_category_id = edh.child_id AND edh.object_type = ''CATEGORY_SET'' AND edh.object_id = mtl.category_set_id
AND mtl.functional_area_id = 11 AND edh.dbi_flag = ''Y'' AND edh.parent_id = &ITEM+ENI_ITEM_VBH_CAT ';
SELECT /*+ leading(c) */
'||l_col1_b||' BIM_SALES_GROUP,
to_char( '||l_col2_b||' ) VIEWBYID,
'||l_col3_b||' is_resource,
sum(rank_a) rank_a,
sum(rank_b) rank_b,
sum(rank_c) rank_c,
sum(rank_d) rank_d,
sum(rank_z) rank_z,
sum(rank_a + rank_b + rank_c + rank_d + rank_z) rank_total,
sum(leads_qualified) leads_qualified
FROM FII_TIME_RPT_STRUCT c , JTF_RS_RESOURCE_EXTNS_VL a, '|| l_tables_b|| '
WHERE c.calendar_id=-1
AND c.report_date = &BIS_CURRENT_ASOF_DATE
AND BITAND(c.record_type_id,:l_record_type)=c.record_type_id
'||l_where_b||'
GROUP BY '||l_col1_b||','||l_col2_b||','||l_col3_b;
l_query := 'SELECT BIM_SALES_GROUP VIEWBY,
VIEWBYID,
RANK_A BIM_ATTRIBUTE1,
RANK_B BIM_ATTRIBUTE2,
RANK_C BIM_ATTRIBUTE3,
RANK_D BIM_ATTRIBUTE4,
RANK_Z BIM_ATTRIBUTE5,
RANK_TOTAL BIM_ATTRIBUTE6,
decode(SUM(RANK_A + RANK_B + RANK_C + RANK_D + RANK_Z) OVER(),0,0,((RANK_TOTAL * 100)/ SUM(RANK_A + RANK_B + RANK_C + RANK_D + RANK_Z) OVER())) BIM_ATTRIBUTE7,
LEADS_QUALIFIED BIM_ATTRIBUTE8,
RANK_A BIM_ATTRIBUTE9,
LEADS_QUALIFIED BIM_ATTRIBUTE13,
DECODE('||''''||l_view_by||''''||', ''ORGANIZATION+JTF_ORG_SALES_GROUP'',DECODE(is_resource,1,NULL,'||''''||l_url_str||''''||' ) ,NULL) BIM_ATTRIBUTE14,
NULL BIM_ATTRIBUTE15,
(RANK_TOTAL - (RANK_A + RANK_B)) BIM_ATTRIBUTE16,
decode(VIEWBYID,null,null,decode(RANK_A,0,NULL,'||''''||l_url_str1||''''||'||'||''''||l_Metric_a||''''||'||'||''''||l_rpt_name||''''||'||VIEWBYID'||'||'||''''||l_context_info||')) BIM_URL1,
decode(VIEWBYID,null,null,decode(RANK_B,0,NULL,'||''''||l_url_str2||''''||'||'||''''||l_Metric_b||''''||'||'||''''||l_rpt_name||''''||'||VIEWBYID'||'||'||''''||l_context_info||')) BIM_URL2,
decode(VIEWBYID,null,null,decode(RANK_C,0,NULL,'||''''||l_url_str3||''''||'||'||''''||l_Metric_c||''''||'||'||''''||l_rpt_name||''''||'||VIEWBYID'||'||'||''''||l_context_info||')) BIM_URL3,
decode(VIEWBYID,null,null,decode(RANK_D,0,NULL,'||''''||l_url_str4||''''||'||'||''''||l_Metric_d||''''||'||'||''''||l_rpt_name||''''||'||VIEWBYID'||'||'||''''||l_context_info||')) BIM_URL4,
decode(VIEWBYID,null,null,decode(RANK_Z,0,NULL,'||''''||l_url_str5||''''||'||'||''''||l_Metric_e||''''||'||'||''''||l_rpt_name||''''||'||VIEWBYID'||'||'||''''||l_context_info||')) BIM_URL5,
SUM(RANK_A) OVER() BIM_GRAND_TOTAL1,
SUM(RANK_B) OVER() BIM_GRAND_TOTAL2,
SUM(RANK_C) OVER() BIM_GRAND_TOTAL3,
SUM(RANK_D) OVER() BIM_GRAND_TOTAL4,
SUM(RANK_Z) OVER() BIM_GRAND_TOTAL5,
SUM(RANK_TOTAL) OVER() BIM_GRAND_TOTAL6,
decode(SUM(RANK_TOTAL) OVER(),0,0,(SUM(RANK_TOTAL) OVER()) * 100/(SUM(RANK_TOTAL) OVER())) BIM_GRAND_TOTAL7,
SUM(LEADS_QUALIFIED) OVER() BIM_GRAND_TOTAL8,
SUM(RANK_A) OVER() BIM_GRAND_TOTAL9,
SUM(LEADS_QUALIFIED) OVER() BIM_GRAND_TOTAL10
FROM
(
SELECT BIM_SALES_GROUP,
VIEWBYID,
is_resource,
sum(rank_a) rank_a,
sum(rank_b) rank_b,
sum(rank_c) rank_c,
sum(rank_d) rank_d,
sum(rank_z) rank_z,
sum(rank_total) rank_total,
sum(leads_qualified) leads_qualified
FROM
(
/*For sales group*/
select /*+ leading(c) */
'||l_col1_a||' BIM_SALES_GROUP,
to_char( '||l_col2_a||' ) VIEWBYID,
'||l_col3_a||' is_resource,
sum(rank_a) rank_a,
sum(rank_b) rank_b,
sum(rank_c) rank_c,
sum(rank_d) rank_d,
sum(rank_z) rank_z,
sum(rank_a + rank_b + rank_c + rank_d + rank_z) rank_total,
sum(leads_qualified) leads_qualified
FROM FII_TIME_RPT_STRUCT c , '|| l_tables_a|| '
WHERE c.calendar_id=-1
AND c.report_date = &BIS_CURRENT_ASOF_DATE
AND BITAND(c.record_type_id,:l_record_type)=c.record_type_id
'||l_where_a||'
GROUP BY '||l_col1_a||','||l_col2_a||','||l_col3_a||l_qry_sg||'
)
GROUP BY BIM_SALES_GROUP,VIEWBYID,is_resource
HAVING SUM(RANK_A) > 0
OR SUM(RANK_B) > 0
OR SUM(RANK_C) > 0
OR SUM(RANK_D) > 0
OR SUM(RANK_Z) > 0
)
&ORDER_BY_CLAUSE';
l_query := 'SELECT BIM_SALES_GROUP VIEWBY,
VIEWBYID,
RANK_A BIM_ATTRIBUTE1,
RANK_B BIM_ATTRIBUTE2,
RANK_C BIM_ATTRIBUTE3,
RANK_D BIM_ATTRIBUTE4,
RANK_Z BIM_ATTRIBUTE5,
RANK_TOTAL BIM_ATTRIBUTE6,
decode(SUM(RANK_A + RANK_B + RANK_C + RANK_D + RANK_Z) OVER(),0,0,((RANK_TOTAL * 100)/ SUM(RANK_A + RANK_B + RANK_C + RANK_D + RANK_Z) OVER())) BIM_ATTRIBUTE7,
LEADS_QUALIFIED BIM_ATTRIBUTE8,
RANK_A BIM_ATTRIBUTE9,
LEADS_QUALIFIED BIM_ATTRIBUTE13,
DECODE('||''''||l_view_by||''''||', ''ORGANIZATION+JTF_ORG_SALES_GROUP'',DECODE(is_resource,1,NULL,'||''''||l_url_str||''''||' ) ,NULL) BIM_ATTRIBUTE14,
NULL BIM_ATTRIBUTE15,
(RANK_TOTAL - (RANK_A + RANK_B)) BIM_ATTRIBUTE16,
decode(VIEWBYID,null,null,decode(RANK_A,0,NULL,'||''''||l_url_str1||''''||'||'||''''||l_Metric_a||''''||'||'||''''||l_rpt_name||''''||'||VIEWBYID'||'||'||''''||l_context_info||')) BIM_URL1,
decode(VIEWBYID,null,null,decode(RANK_B,0,NULL,'||''''||l_url_str2||''''||'||'||''''||l_Metric_b||''''||'||'||''''||l_rpt_name||''''||'||VIEWBYID'||'||'||''''||l_context_info||')) BIM_URL2,
decode(VIEWBYID,null,null,decode(RANK_C,0,NULL,'||''''||l_url_str3||''''||'||'||''''||l_Metric_c||''''||'||'||''''||l_rpt_name||''''||'||VIEWBYID'||'||'||''''||l_context_info||')) BIM_URL3,
decode(VIEWBYID,null,null,decode(RANK_D,0,NULL,'||''''||l_url_str4||''''||'||'||''''||l_Metric_d||''''||'||'||''''||l_rpt_name||''''||'||VIEWBYID'||'||'||''''||l_context_info||')) BIM_URL4,
decode(VIEWBYID,null,null,decode(RANK_Z,0,NULL,'||''''||l_url_str5||''''||'||'||''''||l_Metric_e||''''||'||'||''''||l_rpt_name||''''||'||VIEWBYID'||'||'||''''||l_context_info||')) BIM_URL5,
SUM(RANK_A) OVER() BIM_GRAND_TOTAL1,
SUM(RANK_B) OVER() BIM_GRAND_TOTAL2,
SUM(RANK_C) OVER() BIM_GRAND_TOTAL3,
SUM(RANK_D) OVER() BIM_GRAND_TOTAL4,
SUM(RANK_Z) OVER() BIM_GRAND_TOTAL5,
SUM(RANK_TOTAL) OVER() BIM_GRAND_TOTAL6,
decode(SUM(RANK_TOTAL) OVER(),0,0,(SUM(RANK_TOTAL) OVER()) * 100/(SUM(RANK_TOTAL) OVER())) BIM_GRAND_TOTAL7,
SUM(LEADS_QUALIFIED) OVER() BIM_GRAND_TOTAL8,
SUM(RANK_A) OVER() BIM_GRAND_TOTAL9,
SUM(LEADS_QUALIFIED) OVER() BIM_GRAND_TOTAL10
FROM
(
SELECT BIM_SALES_GROUP,
VIEWBYID,
is_resource,
sum(rank_a) rank_a,
sum(rank_b) rank_b,
sum(rank_c) rank_c,
sum(rank_d) rank_d,
sum(rank_z) rank_z,
sum(rank_total) rank_total,
sum(leads_qualified) leads_qualified
FROM
(
/*For reps*/
SELECT /*+ leading(c) */
'||l_col1_b||' BIM_SALES_GROUP,
to_char('||l_col2_b||' ) VIEWBYID,
'||l_col3_b||' is_resource,
sum(rank_a) rank_a,
sum(rank_b) rank_b,
sum(rank_c) rank_c,
sum(rank_d) rank_d,
sum(rank_z) rank_z,
sum(rank_a + rank_b + rank_c + rank_d + rank_z) rank_total,
sum(leads_qualified) leads_qualified
FROM FII_TIME_RPT_STRUCT c ,JTF_RS_RESOURCE_EXTNS_VL a, '|| l_tables_b|| '
WHERE c.calendar_id=-1
AND c.report_date = &BIS_CURRENT_ASOF_DATE
AND BITAND(c.record_type_id,:l_record_type)=c.record_type_id
'||l_where_b||'
GROUP BY '||l_col1_b||','||l_col2_b||','||l_col3_b||'
)
GROUP BY BIM_SALES_GROUP,VIEWBYID,is_resource
HAVING SUM(RANK_A) > 0
OR SUM(RANK_B) > 0
OR SUM(RANK_C) > 0
OR SUM(RANK_D) > 0
OR SUM(RANK_Z) > 0
)
&ORDER_BY_CLAUSE';
l_query := 'SELECT
NULL VIEWBY,
NULL VIEWBYID,
NULL BIM_MEASURE1,
NULL BIM_MEASURE2,
NULL BIM_MEASURE3,
NULL BIM_MEASURE4,
NULL BIM_MEASURE5,
NULL BIM_MEASURE6,
NULL BIM_MEASURE8,
NULL BIM_MEASURE7,
NULL BIM_MEASURE9,
NULL BIM_URL1,
NULL BIM_URL2,
NULL BIM_URL3,
NULL BIM_URL4,
NULL BIM_URL5,
NULL BIM_URL6,
NULL BIM_URL7,
NULL BIM_GRAND_TOTAL1,
NULL BIM_GRAND_TOTAL2,
NULL BIM_GRAND_TOTAL3,
NULL BIM_GRAND_TOTAL4,
NULL BIM_GRAND_TOTAL5,
NULL BIM_GRAND_TOTAL6,
NULL bim_GRAND_TOTAL7,
NULL bim_GRAND_TOTAL8,
NULL bim_GRAND_TOTAL9
FROM dual';
'SELECT BIM_SALES_GROUP VIEWBY, VIEWBYID,
age_3_below BIM_MEASURE1, age_3_to_7 BIM_MEASURE2,
age_8_to_14 BIM_MEASURE3, age_15_to_21 BIM_MEASURE4,
age_22_to_28 BIM_MEASURE5, age_29_to_35 BIM_MEASURE6,
age_36_to_42 BIM_MEASURE7, age_42_to_above BIM_MEASURE8,
(age_3_below + age_3_to_7 + age_8_to_14 + age_15_to_21 +
age_22_to_28 + age_29_to_35 + age_36_to_42 + age_42_to_above) BIM_MEASURE9,
NULL BIM_MEASURE10,
DECODE(leaf_node_flag,''Y'',NULL,'||''''||l_url_str||''''||' ) BIM_MEASURE11,
decode(VIEWBYID,-1,null,decode(age_3_below,0,NULL,'||''''||l_url_str1||''''||'||'||''''||l_Metric_a||''''||'||'||''''||l_rpt_name||''''||'||VIEWBYID'||'||'||''''||l_context_info||')) BIM_URL1,
decode(VIEWBYID,-1,null,decode(age_3_to_7,0,NULL,'||''''||l_url_str2||''''||'||'||''''||l_Metric_b||''''||'||'||''''||l_rpt_name||''''||'||VIEWBYID'||'||'||''''||l_context_info||')) BIM_URL2,
decode(VIEWBYID,-1,null,decode(age_8_to_14,0,NULL,'||''''||l_url_str3||''''||'||'||''''||l_Metric_c||''''||'||'||''''||l_rpt_name||''''||'||VIEWBYID'||'||'||''''||l_context_info||')) BIM_URL3,
decode(VIEWBYID,-1,null,decode(age_15_to_21,0,NULL,'||''''||l_url_str4||''''||'||'||''''||l_Metric_d||''''||'||'||''''||l_rpt_name||''''||'||VIEWBYID'||'||'||''''||l_context_info||')) BIM_URL4,
decode(VIEWBYID,-1,null,decode(age_22_to_28,0,NULL,'||''''||l_url_str5||''''||'||'||''''||l_Metric_e||''''||'||'||''''||l_rpt_name||''''||'||VIEWBYID'||'||'||''''||l_context_info||')) BIM_URL5,
decode(VIEWBYID,-1,null,decode(age_29_to_35,0,NULL,'||''''||l_url_str6||''''||'||'||''''||l_Metric_f||''''||'||'||''''||l_rpt_name||''''||'||VIEWBYID'||'||'||''''||l_context_info||')) BIM_URL6,
decode(VIEWBYID,-1,null,decode(age_36_to_42,0,NULL,'||''''||l_url_str7||''''||'||'||''''||l_Metric_g||''''||'||'||''''||l_rpt_name||''''||'||VIEWBYID'||'||'||''''||l_context_info||')) BIM_URL7,
decode(VIEWBYID,-1,null,decode(age_42_to_above,0,NULL,'||''''||l_url_str8||''''||'||'||''''||l_Metric_h||''''||'||'||''''||l_rpt_name||''''||'||VIEWBYID'||'||'||''''||l_context_info||')) BIM_URL8,
SUM(age_3_below) over() BIM_GRAND_TOTAL1,
SUM(age_3_to_7) over() BIM_GRAND_TOTAL2,
SUM(age_8_to_14) over() BIM_GRAND_TOTAL3,
SUM(age_15_to_21) over() BIM_GRAND_TOTAL4,
SUM(age_22_to_28) over() BIM_GRAND_TOTAL5,
SUM(age_29_to_35) over() BIM_GRAND_TOTAL6,
SUM(age_36_to_42) over() BIM_GRAND_TOTAL7,
SUM(age_42_to_above) over() BIM_GRAND_TOTAL8,
SUM(age_3_below+age_3_to_7+age_8_to_14+age_15_to_21+age_22_to_28+age_29_to_35+
age_36_to_42+age_42_to_above) over() BIM_GRAND_TOTAL9
FROM (
SELECT e.value BIM_SALES_GROUP,b.product_category_id VIEWBYID,e.leaf_node_flag leaf_node_flag,
sum(age_3_below) age_3_below, sum(age_3_to_7) age_3_to_7, sum(age_8_to_14) age_8_to_14,
sum(age_15_to_21) age_15_to_21, sum(age_22_to_28) age_22_to_28, sum(age_29_to_35) age_29_to_35,
sum(age_36_to_42) age_36_to_42, sum(age_42_to_above) age_42_to_above,
1 row_order
FROM BIM_I_LP_AGE_SG_MV b,ENI_ITEM_VBH_NODES_V e
WHERE
b.group_id = &ORGANIZATION+JTF_ORG_SALES_GROUP
AND e.parent_id = b.product_category_id
AND e.parent_id = e.child_id
AND e.top_node_flag = ''Y''
AND b.resource_id = :l_resource_id
AND b.dim_id=''ALL''
AND b.umark = 1
GROUP BY e.value,b.product_category_id,e.leaf_node_flag
HAVING
SUM(age_3_below) > 0
OR SUM(age_3_to_7) > 0
OR SUM(age_8_to_14) > 0
OR SUM(age_15_to_21) > 0
OR SUM(age_22_to_28) > 0
OR SUM(age_29_to_35) > 0
OR SUM(age_36_to_42) > 0
OR SUM(age_42_to_above) > 0
) &ORDER_BY_CLAUSE';
'SELECT BIM_SALES_GROUP VIEWBY,VIEWBYID,
age_3_below BIM_MEASURE1, age_3_to_7 BIM_MEASURE2,
age_8_to_14 BIM_MEASURE3, age_15_to_21 BIM_MEASURE4,
age_22_to_28 BIM_MEASURE5, age_29_to_35 BIM_MEASURE6,
age_36_to_42 BIM_MEASURE7, age_42_to_above BIM_MEASURE8,
(age_3_below + age_3_to_7 + age_8_to_14 + age_15_to_21 +
age_22_to_28 + age_29_to_35 + age_36_to_42 + age_42_to_above) BIM_MEASURE9,
NULL BIM_MEASURE10,
DECODE(leaf_node_flag,''Y'',NULL,'||''''||l_url_str||''''||' ) BIM_MEASURE11,
decode(VIEWBYID,-1,null,decode(age_3_below,0,NULL,'||''''||l_url_str1||''''||'||'||''''||l_Metric_a||''''||'||'||''''||l_rpt_name||''''||'||VIEWBYID'||'||'||''''||l_context_info||')) BIM_URL1,
decode(VIEWBYID,-1,null,decode(age_3_to_7,0,NULL,'||''''||l_url_str2||''''||'||'||''''||l_Metric_b||''''||'||'||''''||l_rpt_name||''''||'||VIEWBYID'||'||'||''''||l_context_info||')) BIM_URL2,
decode(VIEWBYID,-1,null,decode(age_8_to_14,0,NULL,'||''''||l_url_str3||''''||'||'||''''||l_Metric_c||''''||'||'||''''||l_rpt_name||''''||'||VIEWBYID'||'||'||''''||l_context_info||')) BIM_URL3,
decode(VIEWBYID,-1,null,decode(age_15_to_21,0,NULL,'||''''||l_url_str4||''''||'||'||''''||l_Metric_d||''''||'||'||''''||l_rpt_name||''''||'||VIEWBYID'||'||'||''''||l_context_info||')) BIM_URL4,
decode(VIEWBYID,-1,null,decode(age_22_to_28,0,NULL,'||''''||l_url_str5||''''||'||'||''''||l_Metric_e||''''||'||'||''''||l_rpt_name||''''||'||VIEWBYID'||'||'||''''||l_context_info||')) BIM_URL5,
decode(VIEWBYID,-1,null,decode(age_29_to_35,0,NULL,'||''''||l_url_str6||''''||'||'||''''||l_Metric_f||''''||'||'||''''||l_rpt_name||''''||'||VIEWBYID'||'||'||''''||l_context_info||')) BIM_URL6,
decode(VIEWBYID,-1,null,decode(age_36_to_42,0,NULL,'||''''||l_url_str7||''''||'||'||''''||l_Metric_g||''''||'||'||''''||l_rpt_name||''''||'||VIEWBYID'||'||'||''''||l_context_info||')) BIM_URL7,
decode(VIEWBYID,-1,null,decode(age_42_to_above,0,NULL,'||''''||l_url_str8||''''||'||'||''''||l_Metric_h||''''||'||'||''''||l_rpt_name||''''||'||VIEWBYID'||'||'||''''||l_context_info||')) BIM_URL8,
SUM(age_3_below) over() BIM_GRAND_TOTAL1,
SUM(age_3_to_7) over() BIM_GRAND_TOTAL2,
SUM(age_8_to_14) over() BIM_GRAND_TOTAL3,
SUM(age_15_to_21) over() BIM_GRAND_TOTAL4,
SUM(age_22_to_28) over() BIM_GRAND_TOTAL5,
SUM(age_29_to_35) over() BIM_GRAND_TOTAL6,
SUM(age_36_to_42) over() BIM_GRAND_TOTAL7,
SUM(age_42_to_above) over() BIM_GRAND_TOTAL8,
SUM(age_3_below+age_3_to_7+age_8_to_14+age_15_to_21+age_22_to_28+age_29_to_35+
age_36_to_42+age_42_to_above) over() BIM_GRAND_TOTAL9
FROM (
SELECT e.value BIM_SALES_GROUP,b.product_category_id VIEWBYID,e.leaf_node_flag leaf_node_flag,
sum(age_3_below) age_3_below, sum(age_3_to_7) age_3_to_7, sum(age_8_to_14) age_8_to_14,
sum(age_15_to_21) age_15_to_21, sum(age_22_to_28) age_22_to_28, sum(age_29_to_35) age_29_to_35,
sum(age_36_to_42) age_36_to_42, sum(age_42_to_above) age_42_to_above,
1 row_order
FROM BIM_I_LP_AGE_SG_MV b,ENI_ITEM_VBH_NODES_V e
WHERE
b.group_id = :l_group_id
AND e.parent_id = b.product_category_id
AND e.parent_id = e.child_id
AND e.top_node_flag = ''Y''
AND b.resource_id =:l_resource_id
AND b.dim_id=''ALL''
AND b.umark = 1
GROUP BY e.value,b.product_category_id,e.leaf_node_flag
HAVING
SUM(age_3_below) > 0
OR SUM(age_3_to_7) > 0
OR SUM(age_8_to_14) > 0
OR SUM(age_15_to_21) > 0
OR SUM(age_22_to_28) > 0
OR SUM(age_29_to_35) > 0
OR SUM(age_36_to_42) > 0
OR SUM(age_42_to_above) > 0
) &ORDER_BY_CLAUSE';
/*sales group is selected from the page*/
if l_resource_id is null then
l_query :=
'SELECT BIM_SALES_GROUP VIEWBY,VIEWBYID,
age_3_below BIM_MEASURE1, age_3_to_7 BIM_MEASURE2,
age_8_to_14 BIM_MEASURE3, age_15_to_21 BIM_MEASURE4,
age_22_to_28 BIM_MEASURE5, age_29_to_35 BIM_MEASURE6,
age_36_to_42 BIM_MEASURE7, age_42_to_above BIM_MEASURE8,
(age_3_below + age_3_to_7 + age_8_to_14 + age_15_to_21 +
age_22_to_28 + age_29_to_35 + age_36_to_42 + age_42_to_above) BIM_MEASURE9,
NULL BIM_MEASURE10,
DECODE(leaf_node_flag,''Y'',NULL,'||''''||l_url_str||''''||' ) BIM_MEASURE11,
CASE WHEN VIEWBYID = -1 THEN null WHEN DIR_FLAG=1 THEN NULL WHEN age_3_below = 0 THEN NULL ELSE '||''''||l_url_str1||''''||'||'||''''||l_Metric_a||''''||'||'||''''||l_rpt_name||''''||'||VIEWBYID'||'||'||''''||l_context_info||' END BIM_URL1,
CASE WHEN VIEWBYID = -1 THEN null WHEN DIR_FLAG=1 THEN NULL WHEN age_3_to_7 = 0 THEN NULL ELSE '||''''||l_url_str2||''''||'||'||''''||l_Metric_b||''''||'||'||''''||l_rpt_name||''''||'||VIEWBYID'||'||'||''''||l_context_info||' END BIM_URL2,
CASE WHEN VIEWBYID = -1 THEN null WHEN DIR_FLAG=1 THEN NULL WHEN age_8_to_14 = 0 THEN NULL ELSE '||''''||l_url_str3||''''||'||'||''''||l_Metric_c||''''||'||'||''''||l_rpt_name||''''||'||VIEWBYID'||'||'||''''||l_context_info||' END BIM_URL3,
CASE WHEN VIEWBYID = -1 THEN null WHEN DIR_FLAG=1 THEN NULL WHEN age_15_to_21 = 0 THEN NULL ELSE '||''''||l_url_str4||''''||'||'||''''||l_Metric_d||''''||'||'||''''||l_rpt_name||''''||'||VIEWBYID'||'||'||''''||l_context_info||' END BIM_URL4,
CASE WHEN VIEWBYID = -1 THEN null WHEN DIR_FLAG=1 THEN NULL WHEN age_22_to_28 = 0 THEN NULL ELSE '||''''||l_url_str5||''''||'||'||''''||l_Metric_e||''''||'||'||''''||l_rpt_name||''''||'||VIEWBYID'||'||'||''''||l_context_info||' END BIM_URL5,
CASE WHEN VIEWBYID = -1 THEN null WHEN DIR_FLAG=1 THEN NULL WHEN age_29_to_35 = 0 THEN NULL ELSE '||''''||l_url_str6||''''||'||'||''''||l_Metric_f||''''||'||'||''''||l_rpt_name||''''||'||VIEWBYID'||'||'||''''||l_context_info||' END BIM_URL6,
CASE WHEN VIEWBYID = -1 THEN null WHEN DIR_FLAG=1 THEN NULL WHEN age_36_to_42 = 0 THEN NULL ELSE '||''''||l_url_str7||''''||'||'||''''||l_Metric_g||''''||'||'||''''||l_rpt_name||''''||'||VIEWBYID'||'||'||''''||l_context_info||' END BIM_URL7,
CASE WHEN VIEWBYID = -1 THEN null WHEN DIR_FLAG=1 THEN NULL WHEN age_42_to_above = 0 THEN NULL ELSE '||''''||l_url_str8||''''||'||'||''''||l_Metric_h||''''||'||'||''''||l_rpt_name||''''||'||VIEWBYID'||'||'||''''||l_context_info||' END BIM_URL8,
SUM(age_3_below) over() BIM_GRAND_TOTAL1,
SUM(age_3_to_7) over() BIM_GRAND_TOTAL2,
SUM(age_8_to_14) over() BIM_GRAND_TOTAL3,
SUM(age_15_to_21) over() BIM_GRAND_TOTAL4,
SUM(age_22_to_28) over() BIM_GRAND_TOTAL5,
SUM(age_29_to_35) over() BIM_GRAND_TOTAL6,
SUM(age_36_to_42) over() BIM_GRAND_TOTAL7,
SUM(age_42_to_above) over() BIM_GRAND_TOTAL8,
SUM(age_3_below+age_3_to_7+age_8_to_14+age_15_to_21+age_22_to_28+age_29_to_35+
age_36_to_42+age_42_to_above) over() BIM_GRAND_TOTAL9
FROM (
SELECT e.value BIM_SALES_GROUP,b.product_category_id VIEWBYID,e.leaf_node_flag leaf_node_flag,0 dir_flag,
sum(age_3_below) age_3_below, sum(age_3_to_7) age_3_to_7, sum(age_8_to_14) age_8_to_14,
sum(age_15_to_21) age_15_to_21, sum(age_22_to_28) age_22_to_28, sum(age_29_to_35) age_29_to_35,
sum(age_36_to_42) age_36_to_42, sum(age_42_to_above) age_42_to_above,
1 row_order
FROM BIM_I_LP_AGE_SG_MV b,ENI_ITEM_VBH_NODES_V e
WHERE
b.group_id = &ORGANIZATION+JTF_ORG_SALES_GROUP
AND e.parent_id = &ITEM+ENI_ITEM_VBH_CAT
AND e.id = b.product_category_id
AND e.id = e.child_id
AND((e.leaf_node_flag=''N'' AND e.parent_id<>e.id) OR e.leaf_node_flag=''Y'')
AND b.resource_id = :l_resource_id
AND b.dim_id=''ALL''
AND b.umark = 1
GROUP BY e.value,b.product_category_id,e.leaf_node_flag
HAVING
SUM(age_3_below) > 0
OR SUM(age_3_to_7) > 0
OR SUM(age_8_to_14) > 0
OR SUM(age_15_to_21) > 0
OR SUM(age_22_to_28) > 0
OR SUM(age_29_to_35) > 0
OR SUM(age_36_to_42) > 0
OR SUM(age_42_to_above) > 0
UNION ALL
SELECT bim_pmv_dbi_utl_pkg.get_lookup_value('||''''||'DASS'||''''||')'||' BIM_SALES_GROUP,
b.product_category_id VIEWBYID,e.leaf_node_flag leaf_node_flag,1 dir_flag,
sum(age_3_below) age_3_below, sum(age_3_to_7) age_3_to_7, sum(age_8_to_14) age_8_to_14,
sum(age_15_to_21) age_15_to_21, sum(age_22_to_28) age_22_to_28, sum(age_29_to_35) age_29_to_35,
sum(age_36_to_42) age_36_to_42, sum(age_42_to_above) age_42_to_above,
1 row_order
FROM BIM_I_LP_AGE_SG_MV b,ENI_ITEM_VBH_NODES_V e
WHERE
b.group_id = &ORGANIZATION+JTF_ORG_SALES_GROUP
AND e.parent_id = &ITEM+ENI_ITEM_VBH_CAT
AND e.parent_id = e.child_id
AND e.parent_id = b.product_category_id
AND e.leaf_node_flag <> ''Y''
AND b.resource_id = :l_resource_id
AND b.item_id = ''-1''
AND b.dim_id=''ALL''
AND b.umark = 2
GROUP BY e.value,b.product_category_id,e.leaf_node_flag
HAVING
SUM(age_3_below) > 0
OR SUM(age_3_to_7) > 0
OR SUM(age_8_to_14) > 0
OR SUM(age_15_to_21) > 0
OR SUM(age_22_to_28) > 0
OR SUM(age_29_to_35) > 0
OR SUM(age_36_to_42) > 0
OR SUM(age_42_to_above) > 0
) &ORDER_BY_CLAUSE';
/*sales rep is selected from the page*/
l_query :=
'SELECT BIM_SALES_GROUP VIEWBY,VIEWBYID,
age_3_below BIM_MEASURE1, age_3_to_7 BIM_MEASURE2,
age_8_to_14 BIM_MEASURE3, age_15_to_21 BIM_MEASURE4,
age_22_to_28 BIM_MEASURE5, age_29_to_35 BIM_MEASURE6,
age_36_to_42 BIM_MEASURE7, age_42_to_above BIM_MEASURE8,
(age_3_below + age_3_to_7 + age_8_to_14 + age_15_to_21 +
age_22_to_28 + age_29_to_35 + age_36_to_42 + age_42_to_above) BIM_MEASURE9,
NULL BIM_MEASURE10,
DECODE(leaf_node_flag,''Y'',NULL,'||''''||l_url_str||''''||' ) BIM_MEASURE11,
CASE WHEN VIEWBYID = -1 THEN null WHEN DIR_FLAG=1 THEN NULL WHEN age_3_below = 0 THEN NULL ELSE '||''''||l_url_str1||''''||'||'||''''||l_Metric_a||''''||'||'||''''||l_rpt_name||''''||'||VIEWBYID'||'||'||''''||l_context_info||' END BIM_URL1,
CASE WHEN VIEWBYID = -1 THEN null WHEN DIR_FLAG=1 THEN NULL WHEN age_3_to_7 = 0 THEN NULL ELSE '||''''||l_url_str2||''''||'||'||''''||l_Metric_b||''''||'||'||''''||l_rpt_name||''''||'||VIEWBYID'||'||'||''''||l_context_info||' END BIM_URL2,
CASE WHEN VIEWBYID = -1 THEN null WHEN DIR_FLAG=1 THEN NULL WHEN age_8_to_14 = 0 THEN NULL ELSE '||''''||l_url_str3||''''||'||'||''''||l_Metric_c||''''||'||'||''''||l_rpt_name||''''||'||VIEWBYID'||'||'||''''||l_context_info||' END BIM_URL3,
CASE WHEN VIEWBYID = -1 THEN null WHEN DIR_FLAG=1 THEN NULL WHEN age_15_to_21 = 0 THEN NULL ELSE '||''''||l_url_str4||''''||'||'||''''||l_Metric_d||''''||'||'||''''||l_rpt_name||''''||'||VIEWBYID'||'||'||''''||l_context_info||' END BIM_URL4,
CASE WHEN VIEWBYID = -1 THEN null WHEN DIR_FLAG=1 THEN NULL WHEN age_22_to_28 = 0 THEN NULL ELSE '||''''||l_url_str5||''''||'||'||''''||l_Metric_e||''''||'||'||''''||l_rpt_name||''''||'||VIEWBYID'||'||'||''''||l_context_info||' END BIM_URL5,
CASE WHEN VIEWBYID = -1 THEN null WHEN DIR_FLAG=1 THEN NULL WHEN age_29_to_35 = 0 THEN NULL ELSE '||''''||l_url_str6||''''||'||'||''''||l_Metric_f||''''||'||'||''''||l_rpt_name||''''||'||VIEWBYID'||'||'||''''||l_context_info||' END BIM_URL6,
CASE WHEN VIEWBYID = -1 THEN null WHEN DIR_FLAG=1 THEN NULL WHEN age_36_to_42 = 0 THEN NULL ELSE '||''''||l_url_str7||''''||'||'||''''||l_Metric_g||''''||'||'||''''||l_rpt_name||''''||'||VIEWBYID'||'||'||''''||l_context_info||' END BIM_URL7,
CASE WHEN VIEWBYID = -1 THEN null WHEN DIR_FLAG=1 THEN NULL WHEN age_42_to_above = 0 THEN NULL ELSE '||''''||l_url_str8||''''||'||'||''''||l_Metric_h||''''||'||'||''''||l_rpt_name||''''||'||VIEWBYID'||'||'||''''||l_context_info||' END BIM_URL8,
SUM(age_3_below) over() BIM_GRAND_TOTAL1,
SUM(age_3_to_7) over() BIM_GRAND_TOTAL2,
SUM(age_8_to_14) over() BIM_GRAND_TOTAL3,
SUM(age_15_to_21) over() BIM_GRAND_TOTAL4,
SUM(age_22_to_28) over() BIM_GRAND_TOTAL5,
SUM(age_29_to_35) over() BIM_GRAND_TOTAL6,
SUM(age_36_to_42) over() BIM_GRAND_TOTAL7,
SUM(age_42_to_above) over() BIM_GRAND_TOTAL8,
SUM(age_3_below+age_3_to_7+age_8_to_14+age_15_to_21+age_22_to_28+age_29_to_35+
age_36_to_42+age_42_to_above) over() BIM_GRAND_TOTAL9
FROM (
/*********children of the selected category*********/
SELECT e.value BIM_SALES_GROUP,b.product_category_id VIEWBYID,e.leaf_node_flag leaf_node_flag,0 dir_flag,
sum(age_3_below) age_3_below, sum(age_3_to_7) age_3_to_7, sum(age_8_to_14) age_8_to_14,
sum(age_15_to_21) age_15_to_21, sum(age_22_to_28) age_22_to_28, sum(age_29_to_35) age_29_to_35,
sum(age_36_to_42) age_36_to_42, sum(age_42_to_above) age_42_to_above,
1 row_order
FROM BIM_I_LP_AGE_SG_MV b,ENI_ITEM_VBH_NODES_V e
WHERE
b.group_id = :l_group_id
AND e.parent_id = &ITEM+ENI_ITEM_VBH_CAT
AND e.id = b.product_category_id
AND e.id = e.child_id
AND((e.leaf_node_flag=''N'' AND e.parent_id<>e.id) OR e.leaf_node_flag=''Y'')
AND b.resource_id = :l_resource_id
AND b.dim_id=''ALL''
AND b.umark = 1
GROUP BY e.value,b.product_category_id,e.leaf_node_flag
HAVING
SUM(age_3_below) > 0
OR SUM(age_3_to_7) > 0
OR SUM(age_8_to_14) > 0
OR SUM(age_15_to_21) > 0
OR SUM(age_22_to_28) > 0
OR SUM(age_29_to_35) > 0
OR SUM(age_36_to_42) > 0
OR SUM(age_42_to_above) > 0
UNION ALL
SELECT bim_pmv_dbi_utl_pkg.get_lookup_value('||''''||'DASS'||''''||')'||' BIM_SALES_GROUP,
b.product_category_id VIEWBYID,e.leaf_node_flag leaf_node_flag,1 dir_flag,
sum(age_3_below) age_3_below, sum(age_3_to_7) age_3_to_7, sum(age_8_to_14) age_8_to_14,
sum(age_15_to_21) age_15_to_21, sum(age_22_to_28) age_22_to_28, sum(age_29_to_35) age_29_to_35,
sum(age_36_to_42) age_36_to_42, sum(age_42_to_above) age_42_to_above,
1 row_order
FROM BIM_I_LP_AGE_SG_MV b,ENI_ITEM_VBH_NODES_V e
WHERE
b.group_id = :l_group_id
AND e.parent_id = &ITEM+ENI_ITEM_VBH_CAT
AND e.parent_id = e.child_id
AND e.parent_id = b.product_category_id
AND e.leaf_node_flag <> ''Y''
AND b.resource_id = :l_resource_id
AND b.item_id = ''-1''
AND b.dim_id=''ALL''
AND b.umark = 2
GROUP BY e.value,b.product_category_id,e.leaf_node_flag
HAVING
SUM(age_3_below) > 0
OR SUM(age_3_to_7) > 0
OR SUM(age_8_to_14) > 0
OR SUM(age_15_to_21) > 0
OR SUM(age_22_to_28) > 0
OR SUM(age_29_to_35) > 0
OR SUM(age_36_to_42) > 0
OR SUM(age_42_to_above) > 0
) &ORDER_BY_CLAUSE';
SELECT '||l_col1_a||' BIM_SALES_GROUP,
to_char( '||l_col2_a||' ) VIEWBYID,
'||l_col3_a||' is_resource,
sum(age_3_below) age_3_below ,
SUM(age_3_to_7) age_3_to_7, SUM(age_8_to_14) age_8_to_14,
SUM(age_15_to_21) age_15_to_21 , SUM(age_22_to_28) age_22_to_28, SUM(age_29_to_35) age_29_to_35, SUM(age_36_to_42) age_36_to_42 ,
SUM(age_42_to_above) age_42_to_above ,
1 row_order
FROM JTF_RS_RESOURCE_EXTNS_VL a,'|| l_tables_a|| '
WHERE '||l_where_a||'
GROUP BY '||l_col1_a||','||l_col2_a||','||l_col3_a;
l_query := ' SELECT bim_sales_group VIEWBY, VIEWBYID,
age_3_below BIM_MEASURE1, age_3_to_7 BIM_MEASURE2,
age_8_to_14 BIM_MEASURE3, age_15_to_21 BIM_MEASURE4,
age_22_to_28 BIM_MEASURE5, age_29_to_35 BIM_MEASURE6,
age_36_to_42 BIM_MEASURE7, age_42_to_above BIM_MEASURE8,
(age_3_below + age_3_to_7 + age_8_to_14 + age_15_to_21 +
age_22_to_28 + age_29_to_35 + age_36_to_42 + age_42_to_above) BIM_MEASURE9,
DECODE('||''''||l_view_by||''''||', ''ORGANIZATION+JTF_ORG_SALES_GROUP'',DECODE(is_resource,1,NULL,'||''''||l_url_str||''''||' ) ,NULL) BIM_MEASURE10,
NULL BIM_MEASURE11,
decode(VIEWBYID,null,null,decode(age_3_below,0,NULL,'||''''||l_url_str1||''''||'||'||''''||l_Metric_a||''''||'||'||''''||l_rpt_name||''''||'||VIEWBYID'||'||'||''''||l_context_info||')) BIM_URL1,
decode(VIEWBYID,null,null,decode(age_3_to_7,0,NULL,'||''''||l_url_str2||''''||'||'||''''||l_Metric_b||''''||'||'||''''||l_rpt_name||''''||'||VIEWBYID'||'||'||''''||l_context_info||')) BIM_URL2,
decode(VIEWBYID,null,null,decode(age_8_to_14,0,NULL,'||''''||l_url_str3||''''||'||'||''''||l_Metric_c||''''||'||'||''''||l_rpt_name||''''||'||VIEWBYID'||'||'||''''||l_context_info||')) BIM_URL3,
decode(VIEWBYID,null,null,decode(age_15_to_21,0,NULL,'||''''||l_url_str4||''''||'||'||''''||l_Metric_d||''''||'||'||''''||l_rpt_name||''''||'||VIEWBYID'||'||'||''''||l_context_info||')) BIM_URL4,
decode(VIEWBYID,null,null,decode(age_22_to_28,0,NULL,'||''''||l_url_str5||''''||'||'||''''||l_Metric_e||''''||'||'||''''||l_rpt_name||''''||'||VIEWBYID'||'||'||''''||l_context_info||')) BIM_URL5,
decode(VIEWBYID,null,null,decode(age_29_to_35,0,NULL,'||''''||l_url_str6||''''||'||'||''''||l_Metric_f||''''||'||'||''''||l_rpt_name||''''||'||VIEWBYID'||'||'||''''||l_context_info||')) BIM_URL6,
decode(VIEWBYID,null,null,decode(age_36_to_42,0,NULL,'||''''||l_url_str7||''''||'||'||''''||l_Metric_g||''''||'||'||''''||l_rpt_name||''''||'||VIEWBYID'||'||'||''''||l_context_info||')) BIM_URL7,
decode(VIEWBYID,null,null,decode(age_42_to_above,0,NULL,'||''''||l_url_str8||''''||'||'||''''||l_Metric_h||''''||'||'||''''||l_rpt_name||''''||'||VIEWBYID'||'||'||''''||l_context_info||')) BIM_URL8,
SUM(age_3_below) over() BIM_GRAND_TOTAL1,
SUM(age_3_to_7) over() BIM_GRAND_TOTAL2,
SUM(age_8_to_14) over() BIM_GRAND_TOTAL3,
SUM(age_15_to_21) over() BIM_GRAND_TOTAL4,
SUM(age_22_to_28) over() BIM_GRAND_TOTAL5,
SUM(age_29_to_35) over() BIM_GRAND_TOTAL6,
SUM(age_36_to_42) over() BIM_GRAND_TOTAL7,
SUM(age_42_to_above) over() BIM_GRAND_TOTAL8,
SUM(age_3_below+age_3_to_7+age_8_to_14+age_15_to_21+age_22_to_28+age_29_to_35+
age_36_to_42+age_42_to_above) over() BIM_GRAND_TOTAL9
FROM (
SELECT BIM_SALES_GROUP,VIEWBYID, is_resource,
sum(age_3_below) age_3_below ,
SUM(age_3_to_7) age_3_to_7,
SUM(age_8_to_14) age_8_to_14,
SUM(age_15_to_21) age_15_to_21 ,
SUM(age_22_to_28) age_22_to_28,
SUM(age_29_to_35) age_29_to_35,
SUM(age_36_to_42) age_36_to_42 ,
SUM(age_42_to_above) age_42_to_above
FROM
(
SELECT '||l_col1_b||' BIM_SALES_GROUP,
to_char( '||l_col2_b||' ) VIEWBYID,
'||l_col3_b||' is_resource,
sum(age_3_below) age_3_below ,
SUM(age_3_to_7) age_3_to_7, SUM(age_8_to_14) age_8_to_14,
SUM(age_15_to_21) age_15_to_21 , SUM(age_22_to_28) age_22_to_28, SUM(age_29_to_35) age_29_to_35, SUM(age_36_to_42) age_36_to_42 ,
SUM(age_42_to_above) age_42_to_above ,
2 row_order
FROM '|| l_tables_b|| '
WHERE '||l_where_b||'
GROUP BY '||l_col1_b||','||l_col2_b||','||l_col3_b||l_qry_sg||'
)
GROUP BY BIM_SALES_GROUP,VIEWBYID,is_resource
HAVING
SUM(age_3_below) > 0
OR SUM(age_3_to_7) > 0
OR SUM(age_8_to_14) > 0
OR SUM(age_15_to_21) > 0
OR SUM(age_22_to_28) > 0
OR SUM(age_29_to_35) > 0
OR SUM(age_36_to_42) > 0
OR SUM(age_42_to_above) > 0
) &ORDER_BY_CLAUSE';
l_query := ' SELECT bim_sales_group VIEWBY,
VIEWBYID,
age_3_below BIM_MEASURE1, age_3_to_7 BIM_MEASURE2,
age_8_to_14 BIM_MEASURE3, age_15_to_21 BIM_MEASURE4,
age_22_to_28 BIM_MEASURE5, age_29_to_35 BIM_MEASURE6,
age_36_to_42 BIM_MEASURE7, age_42_to_above BIM_MEASURE8,
(age_3_below + age_3_to_7 + age_8_to_14 + age_15_to_21 +
age_22_to_28 + age_29_to_35 + age_36_to_42 + age_42_to_above) BIM_MEASURE9,
DECODE('||''''||l_view_by||''''||', ''ORGANIZATION+JTF_ORG_SALES_GROUP'',DECODE(is_resource,1,NULL,'||''''||l_url_str||''''||' ) ,NULL) BIM_MEASURE10,
NULL BIM_MEASURE11,
decode(VIEWBYID,null,null,decode(age_3_below,0,NULL,'||''''||l_url_str1||''''||'||'||''''||l_Metric_a||''''||'||'||''''||l_rpt_name||''''||'||VIEWBYID'||'||'||''''||l_context_info||')) BIM_URL1,
decode(VIEWBYID,null,null,decode(age_3_to_7,0,NULL,'||''''||l_url_str2||''''||'||'||''''||l_Metric_b||''''||'||'||''''||l_rpt_name||''''||'||VIEWBYID'||'||'||''''||l_context_info||')) BIM_URL2,
decode(VIEWBYID,null,null,decode(age_8_to_14,0,NULL,'||''''||l_url_str3||''''||'||'||''''||l_Metric_c||''''||'||'||''''||l_rpt_name||''''||'||VIEWBYID'||'||'||''''||l_context_info||')) BIM_URL3,
decode(VIEWBYID,null,null,decode(age_15_to_21,0,NULL,'||''''||l_url_str4||''''||'||'||''''||l_Metric_d||''''||'||'||''''||l_rpt_name||''''||'||VIEWBYID'||'||'||''''||l_context_info||')) BIM_URL4,
decode(VIEWBYID,null,null,decode(age_22_to_28,0,NULL,'||''''||l_url_str5||''''||'||'||''''||l_Metric_e||''''||'||'||''''||l_rpt_name||''''||'||VIEWBYID'||'||'||''''||l_context_info||')) BIM_URL5,
decode(VIEWBYID,null,null,decode(age_29_to_35,0,NULL,'||''''||l_url_str6||''''||'||'||''''||l_Metric_f||''''||'||'||''''||l_rpt_name||''''||'||VIEWBYID'||'||'||''''||l_context_info||')) BIM_URL6,
decode(VIEWBYID,null,null,decode(age_36_to_42,0,NULL,'||''''||l_url_str7||''''||'||'||''''||l_Metric_g||''''||'||'||''''||l_rpt_name||''''||'||VIEWBYID'||'||'||''''||l_context_info||')) BIM_URL7,
decode(VIEWBYID,null,null,decode(age_42_to_above,0,NULL,'||''''||l_url_str8||''''||'||'||''''||l_Metric_h||''''||'||'||''''||l_rpt_name||''''||'||VIEWBYID'||'||'||''''||l_context_info||')) BIM_URL8,
SUM(age_3_below) over() BIM_GRAND_TOTAL1,
SUM(age_3_to_7) over() BIM_GRAND_TOTAL2,
SUM(age_8_to_14) over() BIM_GRAND_TOTAL3,
SUM(age_15_to_21) over() BIM_GRAND_TOTAL4,
SUM(age_22_to_28) over() BIM_GRAND_TOTAL5,
SUM(age_29_to_35) over() BIM_GRAND_TOTAL6,
SUM(age_36_to_42) over() BIM_GRAND_TOTAL7,
SUM(age_42_to_above) over() BIM_GRAND_TOTAL8,
SUM(age_3_below+age_3_to_7+age_8_to_14+age_15_to_21+age_22_to_28+age_29_to_35+
age_36_to_42+age_42_to_above) over() BIM_GRAND_TOTAL9
FROM (
SELECT '||l_col1_a||' BIM_SALES_GROUP,
to_char( '||l_col2_a||' ) VIEWBYID,
'||l_col3_a||' is_resource,
sum(age_3_below) age_3_below ,
SUM(age_3_to_7) age_3_to_7, SUM(age_8_to_14) age_8_to_14,
SUM(age_15_to_21) age_15_to_21 , SUM(age_22_to_28) age_22_to_28, SUM(age_29_to_35) age_29_to_35, SUM(age_36_to_42) age_36_to_42 ,
SUM(age_42_to_above) age_42_to_above ,
1 row_order
FROM JTF_RS_RESOURCE_EXTNS_VL a,'|| l_tables_a|| '
WHERE '||l_where_a||'
GROUP BY '||l_col1_a||','||l_col2_a||','||l_col3_a||'
HAVING
SUM(age_3_below) > 0
OR SUM(age_3_to_7) > 0
OR SUM(age_8_to_14) > 0
OR SUM(age_15_to_21) > 0
OR SUM(age_22_to_28) > 0
OR SUM(age_29_to_35) > 0
OR SUM(age_36_to_42) > 0
OR SUM(age_42_to_above) > 0
) &ORDER_BY_CLAUSE';
l_query:= 'SELECT
NULL VIEWBY,
NULL VIEWBYID,
NULL BIM_MEASURE1,
NULL BIM_MEASURE2,
NULL BIM_MEASURE3,
NULL BIM_MEASURE4,
NULL BIM_MEASURE5,
NULL BIM_MEASURE6,
NULL BIM_MEASURE8,
NULL BIM_MEASURE7,
NULL BIM_MEASURE9,
NULL BIM_URL1,
NULL BIM_URL2,
NULL BIM_URL3,
NULL BIM_URL4,
NULL BIM_URL5,
NULL BIM_URL6,
NULL BIM_URL7,
NULL BIM_GRAND_TOTAL1,
NULL BIM_GRAND_TOTAL2,
NULL BIM_GRAND_TOTAL3,
NULL BIM_GRAND_TOTAL4,
NULL BIM_GRAND_TOTAL5,
NULL BIM_GRAND_TOTAL6,
NULL bim_GRAND_TOTAL7,
NULL bim_GRAND_TOTAL8,
NULL bim_GRAND_TOTAL9
FROM dual';
select name VIEWBY,null BIM_MEASURE2,nvl(sum(leads),0) BIM_MEASURE3,nvl(sum(opportunities),0) BIM_MEASURE4,NULL BIM_MEASURE5,NULL BIM_MEASURE6
FROM ( /*Leads*/
SELECT sum(leads) leads, sum(opportunities) opportunities, start_date, end_date, name
from (
SELECT /*+ leading(fi) */ leads, 0 opportunities, start_date, end_date, name
FROM BIM_I_LD_GEN_SG_MV a,
(SELECT *
FROM (
SELECT id time_id, start_date, end_date, value name
FROM '||l_table_name||'
WHERE end_date < trunc(&BIS_CURRENT_ASOF_DATE)
ORDER BY start_date desc) fi
WHERE rownum <= :l_row_count -1) fi
WHERE a.group_id(+) IN ( &ORGANIZATION+JTF_ORG_SALES_GROUP )
AND a.time_id(+) = fi.time_id
AND a.period_type_id(+) = :l_period_type
AND a.update_time_id(+) =-1
AND a.update_period_type_id(+) =-1
AND a.resource_id(+) = :l_resource_id
UNION ALL /*Opportunity*/
SELECT /*+ leading(fi) */ 0 leads, cnv_opty_amt'||l_curr_suffix||' opportunities, start_date, end_date, name
FROM BIL_BI_OPTY_G_MV a,
(SELECT *
FROM (
SELECT id time_id, start_date, end_date, value name
FROM '||l_table_name||'
WHERE end_date < trunc(&BIS_CURRENT_ASOF_DATE)
ORDER BY start_date desc) fi
WHERE rownum <= :l_row_count -1) fi
WHERE a.effective_time_id(+) = fi.time_id
AND a.parent_sales_group_id(+) = &ORGANIZATION+JTF_ORG_SALES_GROUP
AND a.effective_period_type_id(+) = :l_period_type
)
group by start_date, end_date, name
UNION ALL /*Leads*/
SELECT sum(leads) leads, sum(opportunities) opportunities, start_date, end_date, name
from (
SELECT leads, opportunities, start_date, end_date, name
FROM (SELECT id time_id, start_date, end_date, value name, trunc(&BIS_CURRENT_ASOF_DATE) report_date
FROM '||l_table_name||'
WHERE start_date <= trunc(&BIS_CURRENT_ASOF_DATE)
and end_date >= trunc(&BIS_CURRENT_ASOF_DATE)
ORDER BY start_date desc
) fi,
(SELECT /*+ leading(c) */ SUM(a.leads) leads, 0 opportunities, report_date
FROM (SELECT report_date, time_id, period_type_id
FROM FII_TIME_RPT_STRUCT
WHERE calendar_id = -1
AND report_date = trunc(&BIS_CURRENT_ASOF_DATE)
AND BITAND(record_type_id,:l_record_type) = record_type_id
) c,
BIM_I_LD_GEN_SG_MV a
WHERE a.group_id IN ( &ORGANIZATION+JTF_ORG_SALES_GROUP )
AND a.time_id = c.time_id
AND a.period_type_id = c.period_type_id
AND a.update_time_id =-1
AND a.update_period_type_id =-1
AND a.resource_id =:l_resource_id
GROUP BY report_date) a
where a.report_date(+) = fi.report_date
UNION ALL /*Opportunity*/
SELECT leads, opportunities, start_date, end_date, name
FROM (SELECT id time_id, start_date, end_date, value name,trunc(&BIS_CURRENT_ASOF_DATE) report_date
FROM '||l_table_name||'
WHERE start_date <= trunc(&BIS_CURRENT_ASOF_DATE)
and end_date >= trunc(&BIS_CURRENT_ASOF_DATE)
ORDER BY start_date desc
) fi,
(SELECT /*+ leading(c) */ 0 leads, SUM(a.cnv_opty_amt'||l_curr_suffix||') opportunities, report_date
FROM
(SELECT report_date, time_id, period_type_id
FROM FII_TIME_RPT_STRUCT
WHERE calendar_id = -1
AND report_date = trunc(&BIS_CURRENT_ASOF_DATE)
AND BITAND(record_type_id,:l_record_type) = record_type_id
) c,
BIL_BI_OPTY_G_MV a
WHERE a.effective_time_id = c.time_id
AND a.parent_sales_group_id = &ORGANIZATION+JTF_ORG_SALES_GROUP
AND a.effective_period_type_id = c.period_type_id
GROUP BY report_date) a
where a.report_date(+) = fi.report_date
)
group by start_date, end_date, name
order by start_date asc
)
group by name,start_date
order by start_date';
SELECT NAME VIEWBY,null bim_measure2, nvl(sum(leads), 0) bim_measure3, nvl(sum(opportunities), 0) bim_measure4, NULL bim_measure5, NULL bim_measure6
FROM (
/*Leads*/
SELECT sum(leads) leads, sum(opportunities) opportunities, start_date, end_date, name
FROM (SELECT /*+ leading(fi) */ leads, 0 opportunities, start_date, end_date, name
FROM bim_i_ld_gen_sg_mv a,
(SELECT *
FROM (SELECT ID time_id, start_date, end_date, value name
FROM '||l_table_name||'
WHERE end_date < trunc(&BIS_CURRENT_ASOF_DATE)
ORDER BY start_date desc) fi
WHERE rownum <= :l_row_count - 1) fi
WHERE a.group_id(+) IN (:l_group_id)
AND a.time_id(+) = fi.time_id
AND a.period_type_id(+) = :l_period_type
AND a.update_time_id(+) = -1
AND a.update_period_type_id(+) = -1
AND a.resource_id(+) = :l_resource_id
UNION ALL
/*Opportunity*/
SELECT /*+ leading(fi) */ 0 leads, cnv_opty_amt'||l_curr_suffix||' opportunities, start_date, end_date, name
FROM bil_bi_opty_g_mv a,
(SELECT *
FROM (SELECT ID time_id, start_date, end_date, value name
FROM '||l_table_name||'
WHERE end_date < trunc(&BIS_CURRENT_ASOF_DATE)
ORDER BY start_date desc) fi
WHERE rownum <= :l_row_count - 1) fi
WHERE a.effective_time_id(+) = fi.time_id
AND a.parent_sales_group_id(+) = :l_group_id
AND a.effective_period_type_id(+) = :l_period_type
AND a.salesrep_id(+) = :l_resource_id
)
GROUP BY start_date, end_date, name
UNION ALL
/*Leads*/
SELECT sum(leads) leads, sum(opportunities) opportunities, start_date, end_date, name
FROM (SELECT leads, opportunities, start_date, end_date, name
FROM (SELECT ID time_id, start_date, end_date, value name, trunc(&BIS_CURRENT_ASOF_DATE) report_date
FROM '||l_table_name||'
WHERE start_date <= trunc(&BIS_CURRENT_ASOF_DATE)
AND end_date >= trunc(&BIS_CURRENT_ASOF_DATE)
ORDER BY start_date desc) fi,
(SELECT /*+ leading(c) */ sum(a.leads) leads, 0 opportunities, report_date
FROM (SELECT report_date, time_id, period_type_id
FROM fii_time_rpt_struct
WHERE calendar_id = -1
AND report_date = trunc(&BIS_CURRENT_ASOF_DATE)
AND BITAND(record_type_id, :l_record_type) = record_type_id) c,
bim_i_ld_gen_sg_mv a
WHERE a.group_id IN (:l_group_id)
AND a.time_id = c.time_id
AND a.period_type_id = c.period_type_id
AND a.update_time_id = -1
AND a.update_period_type_id = -1
AND a.resource_id = :l_resource_id
GROUP BY report_date ) a
WHERE a.report_date(+) = fi.report_date
UNION ALL
/*Opportunity*/
SELECT leads, opportunities, start_date, end_date, name
FROM (SELECT ID time_id, start_date, end_date, value name, trunc(&BIS_CURRENT_ASOF_DATE) report_date
FROM '||l_table_name||' a
WHERE start_date <= trunc(&BIS_CURRENT_ASOF_DATE)
AND end_date >= trunc(&BIS_CURRENT_ASOF_DATE)
ORDER BY start_date desc) fi,
(SELECT /*+ leading(c) */ 0 leads, sum(a.cnv_opty_amt'||l_curr_suffix||') opportunities, report_date
FROM (SELECT report_date, time_id, period_type_id
FROM fii_time_rpt_struct
WHERE calendar_id = -1
AND report_date = trunc(&BIS_CURRENT_ASOF_DATE)
AND BITAND (record_type_id, :l_record_type) = record_type_id) c,
bil_bi_opty_g_mv a
WHERE a.effective_time_id = c.time_id
AND a.parent_sales_group_id = :l_group_id
AND a.effective_period_type_id = c.period_type_id
AND a.salesrep_id = :l_resource_id
GROUP BY report_date ) a
WHERE a.report_date(+) = fi.report_date
)
GROUP BY start_date, end_date, name
ORDER BY start_date asc
)
GROUP BY name, start_date
ORDER BY start_date';
l_query:= 'SELECT a.name VIEWBY,null bim_measure2, nvl(sum(a.leads), 0) bim_measure3, nvl(sum(a.opportunities), 0) bim_measure4, nvl(sum(b.leads), 0) bim_measure5, nvl(sum(b.opportunities), 0) bim_measure6
FROM (
/*start of sub table for current values*/
SELECT leads, opportunities, start_date, end_date, name, rownum sequence
FROM ( /*Leads*/
SELECT sum(leads) leads, sum(opportunities) opportunities, start_date, end_date, name
FROM (SELECT /*+ leading(t) */ leads, 0 opportunities, start_date, end_date, name
FROM bim_i_ld_gen_sg_mv a,
(SELECT *
FROM (SELECT ID time_id, start_date, end_date, value name
FROM '||l_table_name||'
WHERE end_date < trunc(&BIS_CURRENT_ASOF_DATE)
ORDER BY start_date desc) t
WHERE rownum <= :l_row_count - 1) t
WHERE a.group_id(+) IN (&ORGANIZATION+JTF_ORG_SALES_GROUP)
AND a.time_id(+) = t.time_id
AND a.period_type_id(+) = :l_period_type
AND a.update_time_id(+) = -1
AND a.update_period_type_id(+) = -1
AND a.resource_id(+) = :l_resource_id
UNION ALL
/*Opportunity*/
SELECT /*+ leading(t) */ 0 leads, cnv_opty_amt'||l_curr_suffix||' opportunities, start_date, end_date, name
FROM bil_bi_opty_g_mv a,
(SELECT *
FROM (SELECT ID time_id, start_date, end_date, value name
FROM '||l_table_name||'
WHERE end_date < trunc(&BIS_CURRENT_ASOF_DATE)
ORDER BY start_date desc) t
WHERE rownum <= :l_row_count - 1) t
WHERE a.effective_time_id(+) = t.time_id
AND a.parent_sales_group_id(+) = &ORGANIZATION+JTF_ORG_SALES_GROUP
AND a.effective_period_type_id(+) = :l_period_type
)
GROUP BY start_date, end_date, name
UNION ALL
/*Leads*/
SELECT sum(leads) leads, sum(opportunities) opportunities, start_date, end_date, name
FROM (SELECT /*+ leading(c) */ leads, opportunities, start_date, end_date, name
FROM (SELECT ID time_id, start_date, end_date, value name, trunc(&BIS_CURRENT_ASOF_DATE) report_date
FROM '||l_table_name||'
WHERE start_date <= trunc(&BIS_CURRENT_ASOF_DATE)
AND end_date >= trunc(&BIS_CURRENT_ASOF_DATE)
ORDER BY start_date desc) t,
(SELECT sum(a.leads) leads, 0 opportunities, report_date
FROM (SELECT report_date, time_id, period_type_id
FROM fii_time_rpt_struct
WHERE calendar_id = -1
AND report_date = trunc(&BIS_CURRENT_ASOF_DATE)
AND BITAND (record_type_id, :l_record_type) = record_type_id) c,
bim_i_ld_gen_sg_mv a
WHERE a.group_id IN (&ORGANIZATION+JTF_ORG_SALES_GROUP)
AND a.time_id = c.time_id
AND a.period_type_id = c.period_type_id
AND a.update_time_id = -1
AND a.update_period_type_id = -1
AND a.resource_id = :l_resource_id
GROUP BY report_date
) a
WHERE a.report_date(+) = t.report_date
UNION ALL
/*Opportunity*/
SELECT /*+ leading(c) */ leads, opportunities, start_date, end_date, name
FROM (SELECT ID time_id, start_date, end_date, value name, trunc (&BIS_CURRENT_ASOF_DATE) report_date
FROM '||l_table_name||'
WHERE start_date <= trunc(&BIS_CURRENT_ASOF_DATE)
AND end_date >= trunc(&BIS_CURRENT_ASOF_DATE)
ORDER BY start_date desc) t,
(SELECT 0 leads, sum(cnv_opty_amt'||l_curr_suffix||') opportunities, report_date
FROM (SELECT report_date, time_id, period_type_id
FROM fii_time_rpt_struct
WHERE calendar_id = -1
AND report_date = trunc(&BIS_CURRENT_ASOF_DATE)
AND BITAND (record_type_id, :l_record_type) = record_type_id) c,
bil_bi_opty_g_mv a
WHERE a.effective_time_id = c.time_id
AND a.parent_sales_group_id = &ORGANIZATION+JTF_ORG_SALES_GROUP
AND a.effective_period_type_id = c.period_type_id
GROUP BY report_date) a
WHERE a.report_date(+) = t.report_date
)
GROUP BY start_date, end_date, name
ORDER BY start_date
)
) a,
(SELECT leads, opportunities, start_date, end_date, name, rownum sequence
FROM ( /*Leads*/
SELECT sum(leads) leads, sum(opportunities) opportunities, start_date, end_date, name
FROM (SELECT /*+ leading(t) */ leads, 0 opportunities, start_date, end_date, name
FROM bim_i_ld_gen_sg_mv a,
(SELECT *
FROM (SELECT ID time_id, start_date, end_date, value name
FROM '||l_table_name||'
WHERE end_date < trunc(&BIS_PREVIOUS_ASOF_DATE)
ORDER BY start_date desc) t
WHERE ROWNUM <= :l_row_count - 1) t
WHERE a.group_id(+) IN (&ORGANIZATION+JTF_ORG_SALES_GROUP)
AND a.time_id(+) = t.time_id
AND a.period_type_id(+) = :l_period_type
AND a.update_time_id(+) = -1
AND a.update_period_type_id(+) = -1
AND a.resource_id(+) = :l_resource_id
UNION ALL
/*Opportunity*/
SELECT /*+ leading(t) */ 0 leads, cnv_opty_amt'||l_curr_suffix||' opportunities, start_date, end_date, name
FROM bil_bi_opty_g_mv a,
(SELECT *
FROM (SELECT ID time_id, start_date, end_date, value name
FROM '||l_table_name||'
WHERE end_date < trunc(&BIS_PREVIOUS_ASOF_DATE)
ORDER BY start_date DESC) t
WHERE ROWNUM <= :l_row_count - 1) t
WHERE a.effective_time_id(+) = t.time_id
AND a.parent_sales_group_id(+) = &ORGANIZATION+JTF_ORG_SALES_GROUP
AND a.effective_period_type_id(+) = :l_period_type
)
GROUP BY start_date, end_date, name
UNION ALL
/*Leads*/
SELECT sum(leads) leads, sum(opportunities) opportunities, start_date, end_date, name
FROM (SELECT leads, opportunities, start_date, end_date, name
FROM (SELECT *
FROM (SELECT ID time_id, start_date, end_date, VALUE name, trunc(&BIS_PREVIOUS_ASOF_DATE) report_date
FROM '||l_table_name||'
WHERE start_date <= trunc(&BIS_PREVIOUS_ASOF_DATE)
AND end_date >= trunc(&BIS_PREVIOUS_ASOF_DATE)
ORDER BY start_date desc) t
WHERE ROWNUM <= 1) t,
(SELECT /*+ leading(c) */sum(nvl(a.leads, 0)) leads, 0 opportunities, report_date
FROM (SELECT report_date, time_id, period_type_id
FROM fii_time_rpt_struct
WHERE calendar_id = -1
AND report_date = trunc(&BIS_PREVIOUS_ASOF_DATE)
AND BITAND (record_type_id, :l_record_type) = record_type_id) c,
bim_i_ld_gen_sg_mv a
WHERE a.group_id IN (&ORGANIZATION+JTF_ORG_SALES_GROUP)
AND a.time_id = c.time_id
AND a.period_type_id = c.period_type_id
AND a.update_time_id = -1
AND a.update_period_type_id = -1
AND a.resource_id = :l_resource_id
GROUP BY report_date) b
WHERE t.report_date = b.report_date(+)
UNION ALL
/*Opportunity*/
SELECT leads, opportunities, start_date, end_date, name
FROM (SELECT *
FROM (SELECT ID time_id, start_date, end_date, VALUE name, trunc(&BIS_PREVIOUS_ASOF_DATE) report_date
FROM '||l_table_name||'
WHERE start_date <= trunc(&BIS_PREVIOUS_ASOF_DATE)
AND end_date >= trunc(&BIS_PREVIOUS_ASOF_DATE)
ORDER BY start_date desc) t
WHERE ROWNUM <= 1) t,
(SELECT /*+ leading(c) */ 0 leads, sum(nvl(a.cnv_opty_amt'||l_curr_suffix||', 0)) opportunities, report_date
FROM (SELECT report_date, time_id, period_type_id
FROM fii_time_rpt_struct
WHERE calendar_id = -1
AND report_date = trunc(&BIS_PREVIOUS_ASOF_DATE)
AND BITAND (record_type_id, :l_record_type) = record_type_id) c,
bil_bi_opty_g_mv a
WHERE a.effective_time_id = c.time_id
AND a.parent_sales_group_id = &ORGANIZATION+JTF_ORG_SALES_GROUP
AND a.effective_period_type_id = c.period_type_id
GROUP BY report_date) b
WHERE t.report_date = b.report_date(+)
)
GROUP BY start_date, end_date, name
ORDER BY start_date
)
) b
WHERE a.sequence = b.sequence
GROUP BY a.name, b.start_date
ORDER BY b.start_date';
l_query:= 'SELECT a.name VIEWBY,null BIM_MEASURE2,NVL(sum(a.leads),0) BIM_MEASURE3,NVL(sum(a.opportunities),0) BIM_MEASURE4,NVL(sum(b.leads),0) BIM_MEASURE5,NVL(sum(b.opportunities),0) BIM_MEASURE6
FROM (
/*start of sub table for current values*/
SELECT leads, opportunities, start_date, end_date, name, rownum sequence
FROM (
SELECT sum(leads) leads, sum(opportunities) opportunities, start_date, end_date, name
from ( /* Leads*/
SELECT /*+ leading(t) */ leads, 0 opportunities, start_date, end_date, name
FROM BIM_I_LD_GEN_SG_MV a,
(SELECT * FROM (select id time_id, start_date, end_date, value name
FROM '||l_table_name||' WHERE end_date < trunc(&BIS_CURRENT_ASOF_DATE)
ORDER BY start_date DESC) t
WHERE rownum <= :l_row_count -1) t
WHERE a.group_id(+) IN ( :l_group_id )
AND a.time_id(+) = t.time_id
AND a.period_type_id(+) = :l_period_type
AND a.update_time_id(+) =-1
AND a.update_period_type_id(+) =-1
AND a.resource_id(+) = :l_resource_id
UNION ALL /*Opportunity*/
SELECT /*+ leading(t) */ 0 leads, cnv_opty_amt'||l_curr_suffix||' opportunities, start_date, end_date, name
FROM BIL_BI_OPTY_G_MV a,
(SELECT * FROM (select id time_id, start_date, end_date, value name
FROM '||l_table_name||' WHERE end_date < trunc(&BIS_CURRENT_ASOF_DATE)
ORDER BY start_date DESC) t
WHERE rownum <= :l_row_count -1) t
WHERE a.effective_time_id(+) = t.time_id
AND a.parent_sales_group_id(+) = :l_group_id
AND a.effective_period_type_id(+) = :l_period_type
AND a.salesrep_id(+) = :l_resource_id
) group by start_date, end_date, name
UNION ALL /*Leads*/
SELECT sum(leads) leads, sum(opportunities) opportunities, start_date, end_date, name
from (
SELECT leads, opportunities, start_date, end_date, name
FROM (SELECT id time_id,start_date,end_date, value name,
trunc(&BIS_CURRENT_ASOF_DATE) report_date
FROM '||l_table_name||' WHERE start_date <= trunc(&BIS_CURRENT_ASOF_DATE)
AND end_date >= trunc(&BIS_CURRENT_ASOF_DATE)
ORDER BY start_date DESC) t,
(SELECT /*+ leading(c) */ SUM(a.leads) leads, 0 opportunities, report_date
FROM (SELECT report_date, time_id, period_type_id
FROM FII_TIME_RPT_STRUCT
WHERE calendar_id = -1
AND report_date = trunc(&BIS_CURRENT_ASOF_DATE)
AND BITAND(record_type_id,:l_record_type) = record_type_id) c,
BIM_I_LD_GEN_SG_MV a
WHERE a.group_id IN (:l_group_id)
AND a.time_id = c.time_id
AND a.period_type_id = c.period_type_id
AND a.update_time_id =-1
AND a.update_period_type_id =-1
AND a.resource_id = :l_resource_id
GROUP BY report_date ) a
WHERE a.report_date(+) = t.report_date
UNION ALL /*Opportunity*/
SELECT leads, opportunities, start_date, end_date, name
FROM (SELECT id time_id,start_date,end_date, value name,
trunc(&BIS_CURRENT_ASOF_DATE) report_date
FROM '||l_table_name||' WHERE start_date <= trunc(&BIS_CURRENT_ASOF_DATE)
AND end_date >= trunc(&BIS_CURRENT_ASOF_DATE)
ORDER BY start_date DESC ) t,
(SELECT /*+ leading(c) */ 0 leads, SUM(cnv_opty_amt'||l_curr_suffix||') opportunities, report_date
FROM (SELECT report_date, time_id, period_type_id
FROM FII_TIME_RPT_STRUCT
WHERE calendar_id = -1
AND report_date = trunc(&BIS_CURRENT_ASOF_DATE)
AND BITAND(record_type_id,:l_record_type) = record_type_id) c,
BIL_BI_OPTY_G_MV a
WHERE a.effective_time_id = c.time_id
AND a.parent_sales_group_id = :l_group_id
AND a.effective_period_type_id = c.period_type_id
AND a.salesrep_id = :l_resource_id
GROUP BY report_date ) a
WHERE a.report_date(+) = t.report_date
) group by start_date, end_date, name
ORDER BY start_date )
) a
,(SELECT leads, opportunities, start_date, end_date, name, rownum sequence
FROM (
SELECT sum(leads) leads, sum(opportunities) opportunities, start_date, end_date, name
from (/*Leads*/
SELECT /*+ leading(t) */ leads, 0 opportunities, start_date, end_date, name
FROM BIM_I_LD_GEN_SG_MV a,
(SELECT * FROM (SELECT id time_id, start_date, end_date, value name
FROM '||l_table_name||' WHERE end_date < trunc(&BIS_PREVIOUS_ASOF_DATE)
ORDER BY start_date DESC
) t where rownum <= :l_row_count -1 ) t
WHERE a.group_id(+) IN (:l_group_id)
AND a.time_id(+) = t.time_id
AND a.period_type_id(+) = :l_period_type
AND a.update_time_id(+) =-1
AND a.update_period_type_id(+) =-1
AND a.resource_id(+) = :l_resource_id
UNION ALL /*Opportunity*/
SELECT /*+ leading(t) */ 0 leads, cnv_opty_amt'||l_curr_suffix||' opportunities, start_date, end_date, name
FROM BIL_BI_OPTY_G_MV a,
(SELECT * FROM (SELECT id time_id, start_date, end_date, value name
FROM '||l_table_name||' WHERE end_date < trunc(&BIS_PREVIOUS_ASOF_DATE)
ORDER BY start_date DESC
) t where rownum <= :l_row_count -1 ) t
WHERE a.effective_time_id(+) = t.time_id
AND a.parent_sales_group_id(+) = :l_group_id
AND a.effective_period_type_id(+) = :l_period_type
AND a.salesrep_id(+) = :l_resource_id
) group by start_date, end_date, name
UNION ALL /*Leads*/
SELECT sum(leads) leads, sum(opportunities) opportunities, start_date, end_date, name from (
SELECT leads, opportunities, start_date, end_date, name
FROM (SELECT * FROM (SELECT id time_id, start_date, end_date, value name,
trunc(&BIS_PREVIOUS_ASOF_DATE) report_date
FROM '||l_table_name||' WHERE start_date <= trunc(&BIS_PREVIOUS_ASOF_DATE)
AND end_date >= trunc(&BIS_PREVIOUS_ASOF_DATE)
ORDER BY start_date desc
) t WHERE rownum <= 1) t,
(SELECT /*+ leading(c) */ SUM(NVL(a.leads,0)) leads, 0 opportunities, report_date
FROM (SELECT report_date, time_id, period_type_id
FROM FII_TIME_RPT_STRUCT
WHERE calendar_id = -1
AND report_date = trunc(&BIS_PREVIOUS_ASOF_DATE)
AND BITAND(record_type_id,:l_record_type) = record_type_id) c,
BIM_I_LD_GEN_SG_MV a
WHERE a.group_id IN ( :l_group_id )
AND a.time_id = c.time_id
AND a.period_type_id = c.period_type_id
AND a.update_time_id =-1
AND a.update_period_type_id =-1
AND a.resource_id = :l_resource_id
GROUP BY report_date
) b WHERE t.report_date = b.report_date(+)
UNION ALL /*Opportunity*/
SELECT leads, opportunities, start_date, end_date, name
FROM (SELECT * FROM (SELECT id time_id, start_date, end_date, value name,
trunc(&BIS_PREVIOUS_ASOF_DATE) report_date
FROM '||l_table_name||' WHERE start_date <= trunc(&BIS_PREVIOUS_ASOF_DATE)
AND end_date >= trunc(&BIS_PREVIOUS_ASOF_DATE)
ORDER BY start_date desc
) t WHERE rownum <= 1) t,
(SELECT /*+ leading(c) */ 0 leads, SUM(NVL(a.cnv_opty_amt'||l_curr_suffix||',0)) opportunities, report_date
FROM (SELECT report_date, time_id, period_type_id
FROM FII_TIME_RPT_STRUCT
WHERE calendar_id = -1
AND report_date = trunc(&BIS_PREVIOUS_ASOF_DATE)
AND BITAND(record_type_id,:l_record_type) = record_type_id) c,
BIL_BI_OPTY_G_MV a
WHERE a.effective_time_id = c.time_id
AND a.parent_sales_group_id = :l_group_id
AND a.effective_period_type_id = c.period_type_id
AND a.salesrep_id = :l_resource_id
GROUP BY report_date
) b WHERE t.report_date = b.report_date(+)
) group by start_date, end_date, name
ORDER BY start_date)) b
WHERE a.sequence = b.sequence
group by a.name,b.start_date
ORDER BY b.START_DATE';
l_query:= 'select name VIEWBY,null BIM_MEASURE2,NVL(sum(leads),0) BIM_MEASURE3,NVL(sum(opportunities),0) BIM_MEASURE4,NULL BIM_MEASURE5,NULL BIM_MEASURE6
FROM ( /*Leads*/
SELECT sum(leads) leads, sum(opportunities) opportunities, start_date, end_date, name
from (
SELECT /*+ leading(fi) */ leads, 0 opportunities, start_date, end_date, name
FROM (
SELECT leads, time_id, period_type_id, update_time_id,update_period_type_id
FROM BIM_I_LP_GEN_SG_MV a , eni_denorm_hierarchies edh,mtl_default_category_sets mtl
WHERE a.group_id(+) IN ( &ORGANIZATION+JTF_ORG_SALES_GROUP )
AND a.product_category_id = edh.child_id AND edh.object_type = ''CATEGORY_SET'' AND edh.object_id = mtl.category_set_id AND mtl.functional_area_id = 11 AND edh.dbi_flag = ''Y'' AND edh.parent_id = &ITEM+ENI_ITEM_VBH_CAT
AND a.resource_id(+) = :l_resource_id
) a,
(SELECT * FROM (
SELECT id time_id, start_date, end_date, value name
FROM '||l_table_name||'
WHERE end_date < trunc(&BIS_CURRENT_ASOF_DATE)
ORDER BY start_date desc) fi
WHERE rownum <= :l_row_count -1) fi
WHERE a.time_id(+) = fi.time_id
AND a.period_type_id(+) = :l_period_type
AND a.update_time_id(+) =-1
AND a.update_period_type_id(+) =-1
UNION ALL /*Opportunity*/
SELECT /*+ leading(fi) */ 0 leads, cnv_opty_amt opportunities, start_date, end_date, name
from (
select cnv_opty_amt'||l_curr_suffix||' cnv_opty_amt, effective_time_id, effective_period_type_id
FROM BIL_BI_OPTY_PG_MV a, eni_denorm_hierarchies edh,mtl_default_category_sets mtl
WHERE a.parent_sales_group_id(+) = &ORGANIZATION+JTF_ORG_SALES_GROUP
AND a.product_category_id = edh.child_id AND edh.object_type = ''CATEGORY_SET'' AND edh.object_id = mtl.category_set_id AND mtl.functional_area_id = 11 AND edh.dbi_flag = ''Y'' AND edh.parent_id = &ITEM+ENI_ITEM_VBH_CAT
) a,
(SELECT * FROM (
SELECT id time_id, start_date, end_date, value name
FROM '||l_table_name||'
WHERE end_date < trunc(&BIS_CURRENT_ASOF_DATE)
ORDER BY start_date desc) fi
WHERE rownum <= :l_row_count -1) fi
WHERE a.effective_time_id(+) = fi.time_id
AND a.effective_period_type_id(+) = :l_period_type
) group by start_date, end_date, name
UNION ALL /*Leads*/
SELECT sum(leads) leads, sum(opportunities) opportunities, start_date, end_date, name
from (
SELECT leads, opportunities, start_date, end_date, name
FROM (SELECT id time_id, start_date, end_date, value name,
trunc(&BIS_CURRENT_ASOF_DATE) report_date
FROM '||l_table_name||'
WHERE start_date <= trunc(&BIS_CURRENT_ASOF_DATE)
and end_date >= trunc(&BIS_CURRENT_ASOF_DATE)
ORDER BY start_date desc
) fi,
(SELECT /*+ leading(c) */ SUM(a.leads) leads, 0 opportunities, report_date
FROM
(SELECT report_date, time_id, period_type_id
FROM FII_TIME_RPT_STRUCT
WHERE calendar_id = -1
AND report_date = trunc(&BIS_CURRENT_ASOF_DATE)
AND BITAND(record_type_id,:l_record_type) = record_type_id
) c,
( SELECT leads, time_id, period_type_id, update_time_id,update_period_type_id
FROM BIM_I_LP_GEN_SG_MV a, eni_denorm_hierarchies edh,mtl_default_category_sets mtl
WHERE a.group_id IN ( &ORGANIZATION+JTF_ORG_SALES_GROUP )
AND a.product_category_id = edh.child_id AND edh.object_type = ''CATEGORY_SET'' AND edh.object_id = mtl.category_set_id AND mtl.functional_area_id = 11 AND edh.dbi_flag = ''Y'' AND edh.parent_id = &ITEM+ENI_ITEM_VBH_CAT
AND a.resource_id = :l_resource_id
) a
WHERE a.time_id = c.time_id
AND a.period_type_id = c.period_type_id
AND a.update_time_id =-1
AND a.update_period_type_id =-1
GROUP BY report_date) a
where a.report_date(+) = fi.report_date
UNION ALL /*Opportunities*/
SELECT leads, opportunities, start_date, end_date, name
FROM (SELECT id time_id, start_date, end_date, value name,
trunc(&BIS_CURRENT_ASOF_DATE) report_date
FROM '||l_table_name||'
WHERE start_date <= trunc(&BIS_CURRENT_ASOF_DATE)
and end_date >= trunc(&BIS_CURRENT_ASOF_DATE)
ORDER BY start_date desc
) fi,
(SELECT /*+ leading(c) */ 0 leads, SUM(a.cnv_opty_amt) opportunities, report_date
FROM
(SELECT report_date, time_id, period_type_id
FROM FII_TIME_RPT_STRUCT
WHERE calendar_id = -1
AND report_date = trunc(&BIS_CURRENT_ASOF_DATE)
AND BITAND(record_type_id,:l_record_type) = record_type_id
) c,
(select cnv_opty_amt'||l_curr_suffix||' cnv_opty_amt, effective_time_id, effective_period_type_id
FROM BIL_BI_OPTY_PG_MV a, eni_denorm_hierarchies edh,mtl_default_category_sets mtl
where a.parent_sales_group_id = &ORGANIZATION+JTF_ORG_SALES_GROUP
AND a.product_category_id = edh.child_id AND edh.object_type = ''CATEGORY_SET'' AND edh.object_id = mtl.category_set_id AND mtl.functional_area_id = 11 AND edh.dbi_flag = ''Y'' AND edh.parent_id = &ITEM+ENI_ITEM_VBH_CAT
) a
WHERE a.effective_time_id = c.time_id
AND a.effective_period_type_id = c.period_type_id
GROUP BY report_date) a
where a.report_date(+) = fi.report_date
) group by start_date, end_date, name
order by start_date asc)
group by name,start_date
order by start_date';
l_query:= 'select name VIEWBY,null BIM_MEASURE2,NVL(sum(leads),0) BIM_MEASURE3,NVL(sum(opportunities),0) BIM_MEASURE4,NULL BIM_MEASURE5,NULL BIM_MEASURE6
FROM (
SELECT sum(leads) leads, sum(opportunities) opportunities, start_date, end_date, name
from (
SELECT /*+ leading(fi) */ leads, 0 opportunities, start_date, end_date, name
FROM (
SELECT leads, time_id, period_type_id, update_time_id,update_period_type_id
FROM BIM_I_LP_GEN_SG_MV a, eni_denorm_hierarchies edh,mtl_default_category_sets mtl
WHERE a.group_id(+) IN ( :l_group_id )
AND a.product_category_id = edh.child_id AND edh.object_type = ''CATEGORY_SET'' AND edh.object_id = mtl.category_set_id AND mtl.functional_area_id = 11 AND edh.dbi_flag = ''Y'' AND edh.parent_id = &ITEM+ENI_ITEM_VBH_CAT
AND a.resource_id(+) =:l_resource_id
) a,
(SELECT * FROM (
SELECT id time_id, start_date, end_date, value name
FROM '||l_table_name||'
WHERE end_date < trunc(&BIS_CURRENT_ASOF_DATE)
ORDER BY start_date desc) fi
WHERE rownum <= :l_row_count -1) fi
WHERE a.time_id(+) = fi.time_id
AND a.period_type_id(+) = :l_period_type
AND a.update_time_id(+) =-1
AND a.update_period_type_id(+) =-1
UNION ALL /*Opportunity*/
SELECT /*+ leading(fi) */ 0 leads, cnv_opty_amt opportunities, start_date, end_date, name
from (
select cnv_opty_amt'||l_curr_suffix||' cnv_opty_amt, effective_time_id, effective_period_type_id
FROM BIL_BI_OPTY_PG_MV a, eni_denorm_hierarchies edh,mtl_default_category_sets mtl
WHERE a.parent_sales_group_id(+) = :l_group_id
AND a.product_category_id = edh.child_id AND edh.object_type = ''CATEGORY_SET'' AND edh.object_id = mtl.category_set_id AND mtl.functional_area_id = 11 AND edh.dbi_flag = ''Y'' AND edh.parent_id = &ITEM+ENI_ITEM_VBH_CAT
AND a.salesrep_id(+) = :l_resource_id
) a,
(SELECT * FROM (
SELECT id time_id, start_date, end_date, value name
FROM '||l_table_name||'
WHERE end_date < trunc(&BIS_CURRENT_ASOF_DATE)
ORDER BY start_date desc) fi
WHERE rownum <= :l_row_count -1) fi
WHERE a.effective_time_id(+) = fi.time_id
AND a.effective_period_type_id(+) = :l_period_type
) group by start_date, end_date, name
UNION ALL /*Leads*/
SELECT sum(leads) leads, sum(opportunities) opportunities, start_date, end_date, name
from (
SELECT leads, opportunities, start_date, end_date, name
FROM (SELECT id time_id, start_date, end_date, value name,
trunc(&BIS_CURRENT_ASOF_DATE) report_date
FROM '||l_table_name||'
WHERE start_date <= trunc(&BIS_CURRENT_ASOF_DATE)
and end_date >= trunc(&BIS_CURRENT_ASOF_DATE)
ORDER BY start_date desc
) fi,
(SELECT /*+ leading(c) */ SUM(a.leads) leads, 0 opportunities, report_date
FROM
(SELECT report_date, time_id, period_type_id
FROM FII_TIME_RPT_STRUCT
WHERE calendar_id = -1
AND report_date = trunc(&BIS_CURRENT_ASOF_DATE)
AND BITAND(record_type_id,:l_record_type) = record_type_id
) c,
( SELECT leads, time_id, period_type_id,update_time_id,update_period_type_id
FROM BIM_I_LP_GEN_SG_MV a, eni_denorm_hierarchies edh,mtl_default_category_sets mtl
WHERE a.group_id IN ( :l_group_id )
AND a.resource_id = :l_resource_id
AND a.product_category_id = edh.child_id AND edh.object_type = ''CATEGORY_SET'' AND edh.object_id = mtl.category_set_id AND mtl.functional_area_id = 11 AND edh.dbi_flag = ''Y'' AND edh.parent_id = &ITEM+ENI_ITEM_VBH_CAT
) a
WHERE a.time_id = c.time_id
AND a.period_type_id = c.period_type_id
AND a.update_time_id =-1
AND a.update_period_type_id =-1
GROUP BY report_date) a
where a.report_date(+) = fi.report_date
UNION ALL /*Opportunities*/
SELECT leads, opportunities, start_date, end_date, name
FROM (SELECT id time_id, start_date, end_date, value name,
trunc(&BIS_CURRENT_ASOF_DATE) report_date
FROM '||l_table_name||'
WHERE start_date <= trunc(&BIS_CURRENT_ASOF_DATE)
and end_date >= trunc(&BIS_CURRENT_ASOF_DATE)
ORDER BY start_date desc
) fi,
(SELECT /*+ leading(c) */ 0 leads, SUM(a.cnv_opty_amt) opportunities, report_date
FROM
(SELECT report_date, time_id, period_type_id
FROM FII_TIME_RPT_STRUCT
WHERE calendar_id = -1
AND report_date = trunc(&BIS_CURRENT_ASOF_DATE)
AND BITAND(record_type_id,:l_record_type) = record_type_id
) c,
(select cnv_opty_amt'||l_curr_suffix||' cnv_opty_amt, effective_time_id, effective_period_type_id
FROM BIL_BI_OPTY_PG_MV a, eni_denorm_hierarchies edh,mtl_default_category_sets mtl
WHERE a.parent_sales_group_id = :l_group_id
AND a.product_category_id = edh.child_id AND edh.object_type = ''CATEGORY_SET'' AND edh.object_id = mtl.category_set_id AND mtl.functional_area_id = 11 AND edh.dbi_flag = ''Y'' AND edh.parent_id = &ITEM+ENI_ITEM_VBH_CAT
AND a.salesrep_id = :l_resource_id
) a
WHERE a.effective_time_id = c.time_id
AND a.effective_period_type_id = c.period_type_id
GROUP BY report_date) a
where a.report_date(+) = fi.report_date
) group by start_date, end_date, name
order by start_date asc)
group by name,start_date
order by start_date';
l_query:= 'SELECT a.name VIEWBY,null BIM_MEASURE2,NVL(sum(a.leads),0) BIM_MEASURE3,NVL(sum(a.opportunities),0) BIM_MEASURE4,NVL(sum(b.leads),0) BIM_MEASURE5,NVL(sum(b.opportunities),0) BIM_MEASURE6
FROM (
SELECT sum(leads) leads, sum(opportunities) opportunities, start_date, end_date, name, rownum sequence
FROM (
SELECT sum(leads) leads, sum(opportunities) opportunities, start_date, end_date, name
from (
SELECT /*+ leading(t) */ sum(leads) leads, 0 opportunities, start_date, end_date, name
FROM (
SELECT leads, time_id, period_type_id, update_time_id,update_period_type_id
FROM BIM_I_LP_GEN_SG_MV a, eni_denorm_hierarchies edh,mtl_default_category_sets mtl
WHERE a.group_id(+) IN ( &ORGANIZATION+JTF_ORG_SALES_GROUP )
AND a.product_category_id = edh.child_id AND edh.object_type = ''CATEGORY_SET'' AND edh.object_id = mtl.category_set_id AND mtl.functional_area_id = 11 AND edh.dbi_flag = ''Y'' AND edh.parent_id = &ITEM+ENI_ITEM_VBH_CAT
AND a.resource_id(+) = :l_resource_id
) a,
(SELECT * FROM (select id time_id, start_date, end_date, value name
FROM '||l_table_name||'
WHERE end_date < trunc(&BIS_CURRENT_ASOF_DATE)
ORDER BY start_date DESC) t
WHERE rownum <= :l_row_count -1) t
WHERE a.time_id(+) = t.time_id
AND a.period_type_id(+) = :l_period_type
AND a.update_time_id(+) =-1
AND a.update_period_type_id(+) =-1
group by name,start_date, end_date
UNION ALL /*Opportunity*/
SELECT /*+ leading(t) */ 0 leads, sum(cnv_opty_amt) opportunities, start_date, end_date, name
FROM (
select cnv_opty_amt'||l_curr_suffix||' cnv_opty_amt, effective_time_id, effective_period_type_id
FROM BIL_BI_OPTY_PG_MV a, eni_denorm_hierarchies edh,mtl_default_category_sets mtl
WHERE a.parent_sales_group_id(+) = &ORGANIZATION+JTF_ORG_SALES_GROUP
AND a.product_category_id = edh.child_id AND edh.object_type = ''CATEGORY_SET'' AND edh.object_id = mtl.category_set_id AND mtl.functional_area_id = 11 AND edh.dbi_flag = ''Y'' AND edh.parent_id = &ITEM+ENI_ITEM_VBH_CAT
) a,
(SELECT * FROM (select id time_id, start_date, end_date, value name
FROM '||l_table_name||' WHERE end_date < trunc(&BIS_CURRENT_ASOF_DATE)
ORDER BY start_date DESC) t
WHERE rownum <= :l_row_count -1) t
WHERE a.effective_time_id(+) = t.time_id
AND a.effective_period_type_id(+) = :l_period_type
group by name,start_date, end_date
) group by start_date, end_date, name
UNION ALL /*Leads*/
SELECT sum(leads) leads, sum(opportunities) opportunities, start_date, end_date, name
from (
SELECT leads, opportunities, start_date, end_date, name
FROM (SELECT id time_id,start_date,end_date, value name,
trunc(&BIS_CURRENT_ASOF_DATE) report_date
FROM '||l_table_name||'
WHERE start_date <= trunc(&BIS_CURRENT_ASOF_DATE)
AND end_date >= trunc(&BIS_CURRENT_ASOF_DATE)
ORDER BY start_date DESC
) t,
(SELECT /*+ leading(c) */ SUM(a.leads) leads, 0 opportunities, report_date
FROM (
SELECT report_date, time_id, period_type_id
FROM FII_TIME_RPT_STRUCT
WHERE calendar_id = -1
AND report_date = trunc(&BIS_CURRENT_ASOF_DATE)
AND BITAND(record_type_id,:l_record_type) = record_type_id
) c,
( SELECT leads, time_id, period_type_id, update_time_id,update_period_type_id
FROM BIM_I_LP_GEN_SG_MV a, eni_denorm_hierarchies edh,mtl_default_category_sets mtl
WHERE a.group_id IN (&ORGANIZATION+JTF_ORG_SALES_GROUP)
AND a.product_category_id = edh.child_id AND edh.object_type = ''CATEGORY_SET'' AND edh.object_id = mtl.category_set_id AND mtl.functional_area_id = 11 AND edh.dbi_flag = ''Y'' AND edh.parent_id = &ITEM+ENI_ITEM_VBH_CAT
AND a.resource_id = :l_resource_id
) a
WHERE a.time_id = c.time_id
AND a.period_type_id = c.period_type_id
AND a.update_time_id =-1
AND a.update_period_type_id =-1
GROUP BY report_date) a
WHERE a.report_date(+) = t.report_date
UNION ALL /*Opportunity*/
SELECT leads, opportunities, start_date, end_date, name
FROM (SELECT id time_id,start_date,end_date, value name,
trunc(&BIS_CURRENT_ASOF_DATE) report_date
FROM '||l_table_name||'
WHERE start_date <= trunc(&BIS_CURRENT_ASOF_DATE)
AND end_date >= trunc(&BIS_CURRENT_ASOF_DATE)
ORDER BY start_date DESC
) t,
(SELECT /*+ leading(c) */ 0 leads, SUM(cnv_opty_amt) opportunities, report_date
FROM (
SELECT report_date, time_id, period_type_id
FROM FII_TIME_RPT_STRUCT
WHERE calendar_id = -1
AND report_date = trunc(&BIS_CURRENT_ASOF_DATE)
AND BITAND(record_type_id,:l_record_type) = record_type_id
) c,
(select cnv_opty_amt'||l_curr_suffix||' cnv_opty_amt, effective_time_id, effective_period_type_id
FROM BIL_BI_OPTY_PG_MV a, eni_denorm_hierarchies edh,mtl_default_category_sets mtl
WHERE a.parent_sales_group_id = &ORGANIZATION+JTF_ORG_SALES_GROUP
AND a.product_category_id = edh.child_id AND edh.object_type = ''CATEGORY_SET'' AND edh.object_id = mtl.category_set_id AND mtl.functional_area_id = 11 AND edh.dbi_flag = ''Y'' AND edh.parent_id = &ITEM+ENI_ITEM_VBH_CAT
) a
WHERE a.effective_time_id = c.time_id
AND a.effective_period_type_id = c.period_type_id
GROUP BY report_date) a
WHERE a.report_date(+) = t.report_date
) group by start_date, end_date, name
ORDER BY start_date)
group by start_date, end_date, name, rownum ) a
/*end of table that fetches current values named as a*/
,(SELECT sum(leads) leads, sum(opportunities) opportunities, start_date, end_date, name, rownum sequence
FROM ( /*Leads*/
SELECT sum(leads) leads, sum(opportunities) opportunities, start_date, end_date, name
from (
SELECT /*+ leading(t) */ sum(leads) leads, 0 opportunities, start_date, end_date, name
FROM (
SELECT leads, time_id, period_type_id, update_time_id,update_period_type_id
FROM BIM_I_LP_GEN_SG_MV a, eni_denorm_hierarchies edh,mtl_default_category_sets mtl
WHERE a.group_id(+) IN (&ORGANIZATION+JTF_ORG_SALES_GROUP)
AND a.product_category_id = edh.child_id AND edh.object_type = ''CATEGORY_SET'' AND edh.object_id = mtl.category_set_id AND mtl.functional_area_id = 11 AND edh.dbi_flag = ''Y'' AND edh.parent_id = &ITEM+ENI_ITEM_VBH_CAT
AND a.resource_id(+) = :l_resource_id
) a,
(SELECT * FROM
(SELECT id time_id, start_date, end_date, value name
FROM '||l_table_name||'
WHERE end_date < trunc(&BIS_PREVIOUS_ASOF_DATE)
ORDER BY start_date DESC) t
where rownum <= :l_row_count -1) t
WHERE a.time_id(+) = t.time_id
AND a.period_type_id(+) = :l_period_type
AND a.update_time_id(+) =-1
AND a.update_period_type_id(+) =-1
group by name,start_date, end_date
UNION ALL /*Opportunity*/
SELECT /*+ leading(t) */ 0 leads, sum(cnv_opty_amt) opportunities, start_date, end_date, name
from (
select cnv_opty_amt'||l_curr_suffix||' cnv_opty_amt, effective_time_id, effective_period_type_id
FROM BIL_BI_OPTY_PG_MV a, eni_denorm_hierarchies edh,mtl_default_category_sets mtl
WHERE a.parent_sales_group_id(+) = &ORGANIZATION+JTF_ORG_SALES_GROUP
AND a.product_category_id= edh.child_id AND edh.object_type = ''CATEGORY_SET'' AND edh.object_id = mtl.category_set_id AND mtl.functional_area_id = 11 AND edh.dbi_flag = ''Y'' AND edh.parent_id = &ITEM+ENI_ITEM_VBH_CAT
) a,
(SELECT * FROM
(SELECT id time_id, start_date, end_date, value name
FROM '||l_table_name||'
WHERE end_date < trunc(&BIS_PREVIOUS_ASOF_DATE)
ORDER BY start_date DESC) t
where rownum <= :l_row_count -1) t
WHERE a.effective_time_id(+) = t.time_id
AND a.effective_period_type_id(+) = :l_period_type
group by name,start_date, end_date
) group by start_date, end_date, name
UNION ALL /*Leads*/
SELECT sum(leads) leads, sum(opportunities) opportunities, start_date, end_date, name
from (
SELECT leads, opportunities, start_date, end_date, name
FROM (SELECT * FROM (SELECT id time_id, start_date, end_date, value name,
trunc(&BIS_PREVIOUS_ASOF_DATE) report_date
FROM '||l_table_name||'
WHERE start_date <= trunc(&BIS_PREVIOUS_ASOF_DATE)
AND end_date >= trunc(&BIS_PREVIOUS_ASOF_DATE)
ORDER BY start_date desc
) t WHERE rownum <= 1) t,
(SELECT /*+ leading(c) */ SUM(NVL(a.leads,0)) leads, 0 opportunities, report_date
FROM
(SELECT report_date, time_id, period_type_id
FROM FII_TIME_RPT_STRUCT
WHERE calendar_id = -1
AND report_date = trunc(&BIS_PREVIOUS_ASOF_DATE)
AND BITAND(record_type_id,:l_record_type) = record_type_id
) c,
( SELECT leads, time_id, period_type_id, update_time_id,update_period_type_id
FROM BIM_I_LP_GEN_SG_MV a, eni_denorm_hierarchies edh,mtl_default_category_sets mtl
WHERE a.group_id IN ( &ORGANIZATION+JTF_ORG_SALES_GROUP )
AND a.product_category_id = edh.child_id AND edh.object_type = ''CATEGORY_SET'' AND edh.object_id = mtl.category_set_id AND mtl.functional_area_id = 11 AND edh.dbi_flag = ''Y'' AND edh.parent_id = &ITEM+ENI_ITEM_VBH_CAT
AND a.resource_id = :l_resource_id
) a
WHERE a.time_id = c.time_id
AND a.period_type_id = c.period_type_id
AND a.update_time_id =-1
AND a.update_period_type_id =-1
GROUP BY report_date) b
WHERE t.report_date = b.report_date(+)
UNION ALL /*Opportunity*/
SELECT leads, opportunities, start_date, end_date, name
FROM (SELECT * FROM (SELECT id time_id, start_date, end_date, value name,
trunc(&BIS_PREVIOUS_ASOF_DATE) report_date
FROM '||l_table_name||'
WHERE start_date <= trunc(&BIS_PREVIOUS_ASOF_DATE)
AND end_date >= trunc(&BIS_PREVIOUS_ASOF_DATE)
ORDER BY start_date desc
) t WHERE rownum <= 1) t,
(SELECT /*+ leading(c) */ 0 leads, SUM(NVL(a.cnv_opty_amt,0)) opportunities, report_date
FROM
(SELECT report_date, time_id, period_type_id
FROM FII_TIME_RPT_STRUCT
WHERE calendar_id = -1
AND report_date = trunc(&BIS_PREVIOUS_ASOF_DATE)
AND BITAND(record_type_id,:l_record_type) = record_type_id) c,
(select cnv_opty_amt, effective_time_id, effective_period_type_id
FROM BIL_BI_OPTY_PG_MV a, eni_denorm_hierarchies edh,mtl_default_category_sets mtl
WHERE a.parent_sales_group_id = &ORGANIZATION+JTF_ORG_SALES_GROUP
AND a.product_category_id = edh.child_id AND edh.object_type = ''CATEGORY_SET'' AND edh.object_id = mtl.category_set_id AND mtl.functional_area_id = 11 AND edh.dbi_flag = ''Y'' AND edh.parent_id = &ITEM+ENI_ITEM_VBH_CAT
) a
WHERE a.effective_time_id = c.time_id
AND a.effective_period_type_id = c.period_type_id
GROUP BY report_date) b
WHERE t.report_date = b.report_date(+)
) group by start_date, end_date, name
ORDER BY start_date)
group by start_date, end_date, name, rownum) b
WHERE a.sequence = b.sequence(+)
group by a.name,b.start_date
order by b.start_date';
l_query:= 'SELECT a.name VIEWBY,null BIM_MEASURE2,NVL(sum(a.leads),0) BIM_MEASURE3,NVL(sum(a.opportunities),0) BIM_MEASURE4,NVL(sum(b.leads),0) BIM_MEASURE5,NVL(sum(b.opportunities),0) BIM_MEASURE6
FROM (
SELECT sum(leads) leads, sum(opportunities) opportunities, start_date, end_date, name, rownum sequence
FROM ( /*Leads*/
SELECT sum(leads) leads, sum(opportunities) opportunities, start_date, end_date, name
from (
SELECT /*+ leading(t) */ sum(leads) leads, 0 opportunities, start_date, end_date, name
FROM (
SELECT leads, time_id, period_type_id, update_time_id,update_period_type_id
FROM BIM_I_LP_GEN_SG_MV a, eni_denorm_hierarchies edh,mtl_default_category_sets mtl
WHERE a.group_id(+) IN ( :l_group_id )
AND a.product_category_id = edh.child_id AND edh.object_type = ''CATEGORY_SET'' AND edh.object_id = mtl.category_set_id AND mtl.functional_area_id = 11 AND edh.dbi_flag = ''Y'' AND edh.parent_id = &ITEM+ENI_ITEM_VBH_CAT
AND a.resource_id(+) = :l_resource_id
) a,
(SELECT * FROM (
select id time_id, start_date, end_date, value name
FROM '||l_table_name||'
WHERE end_date < trunc(&BIS_CURRENT_ASOF_DATE)
ORDER BY start_date DESC) t
WHERE rownum <= :l_row_count -1) t
WHERE a.time_id(+) = t.time_id
AND a.period_type_id(+) = :l_period_type
AND a.update_time_id(+) =-1
AND a.update_period_type_id(+) =-1
group by name,start_date, end_date
UNION ALL /*Opportunities*/
SELECT /*+ leading(t) */ 0 leads, sum(cnv_opty_amt) opportunities, start_date, end_date, name
FROM (
select cnv_opty_amt'||l_curr_suffix||' cnv_opty_amt, effective_time_id, effective_period_type_id
FROM BIL_BI_OPTY_PG_MV a, eni_denorm_hierarchies edh,mtl_default_category_sets mtl
WHERE a.parent_sales_group_id(+) = :l_group_id
AND a.product_category_id = edh.child_id AND edh.object_type = ''CATEGORY_SET'' AND edh.object_id = mtl.category_set_id AND mtl.functional_area_id = 11 AND edh.dbi_flag = ''Y'' AND edh.parent_id = &ITEM+ENI_ITEM_VBH_CAT
AND a.salesrep_id(+) = :l_resource_id
) a,
(SELECT * FROM (
select id time_id, start_date, end_date, value name
FROM '||l_table_name||'
WHERE end_date < trunc(&BIS_CURRENT_ASOF_DATE)
ORDER BY start_date DESC) t
WHERE rownum <= :l_row_count -1) t
WHERE a.effective_time_id(+) = t.time_id
AND a.effective_period_type_id(+) = :l_period_type
group by name,start_date, end_date
) group by start_date, end_date, name
UNION ALL /*Leads*/
SELECT sum(leads) leads, sum(opportunities) opportunities, start_date, end_date, name
from (
SELECT leads, opportunities, start_date, end_date, name
FROM (SELECT id time_id,start_date,end_date, value name,
trunc(&BIS_CURRENT_ASOF_DATE) report_date
FROM '||l_table_name||'
WHERE start_date <= trunc(&BIS_CURRENT_ASOF_DATE)
AND end_date >= trunc(&BIS_CURRENT_ASOF_DATE)
ORDER BY start_date DESC
) t,
(SELECT /*+ leading(c) */ SUM(a.leads) leads, 0 opportunities, report_date
FROM
(SELECT report_date, time_id, period_type_id
FROM FII_TIME_RPT_STRUCT
WHERE calendar_id = -1
AND report_date = trunc(&BIS_CURRENT_ASOF_DATE)
AND BITAND(record_type_id,:l_record_type) = record_type_id
) c,
( SELECT leads, time_id, period_type_id, update_time_id,update_period_type_id
FROM BIM_I_LP_GEN_SG_MV a, eni_denorm_hierarchies edh,mtl_default_category_sets mtl
WHERE a.group_id IN (:l_group_id)
AND a.product_category_id = edh.child_id AND edh.object_type = ''CATEGORY_SET'' AND edh.object_id = mtl.category_set_id AND mtl.functional_area_id = 11 AND edh.dbi_flag = ''Y'' AND edh.parent_id = &ITEM+ENI_ITEM_VBH_CAT
AND a.resource_id =:l_resource_id
) a
WHERE a.time_id = c.time_id
AND a.period_type_id = c.period_type_id
AND a.update_time_id =-1
AND a.update_period_type_id =-1
GROUP BY report_date) a
WHERE a.report_date(+) = t.report_date
UNION ALL /*Opportunity*/
SELECT leads, opportunities, start_date, end_date, name
FROM (SELECT id time_id,start_date,end_date, value name,
trunc(&BIS_CURRENT_ASOF_DATE) report_date
FROM '||l_table_name||'
WHERE start_date <= trunc(&BIS_CURRENT_ASOF_DATE)
AND end_date >= trunc(&BIS_CURRENT_ASOF_DATE)
ORDER BY start_date DESC
) t,
(SELECT /*+ leading(c) */ 0 leads, SUM(cnv_opty_amt) opportunities, report_date
FROM
(SELECT report_date, time_id, period_type_id
FROM FII_TIME_RPT_STRUCT
WHERE calendar_id = -1
AND report_date = trunc(&BIS_CURRENT_ASOF_DATE)
AND BITAND(record_type_id,:l_record_type) = record_type_id
) c,
(select cnv_opty_amt'||l_curr_suffix||' cnv_opty_amt, effective_time_id, effective_period_type_id
FROM BIL_BI_OPTY_PG_MV a, eni_denorm_hierarchies edh,mtl_default_category_sets mtl
WHERE a.parent_sales_group_id = :l_group_id
AND a.product_category_id = edh.child_id AND edh.object_type = ''CATEGORY_SET'' AND edh.object_id = mtl.category_set_id AND mtl.functional_area_id = 11 AND edh.dbi_flag = ''Y'' AND edh.parent_id = &ITEM+ENI_ITEM_VBH_CAT
AND a.salesrep_id = :l_resource_id
) a
WHERE a.effective_time_id = c.time_id
AND a.effective_period_type_id = c.period_type_id
GROUP BY report_date) a
WHERE a.report_date(+) = t.report_date
)group by start_date, end_date, name
ORDER BY start_date)
group by start_date, end_date, name, rownum ) a
/*end of table that fetches current values named as a*/
,(SELECT sum(leads) leads, sum(opportunities) opportunities, start_date, end_date, name, rownum sequence
FROM (/*Leads*/
SELECT sum(leads) leads, sum(opportunities) opportunities, start_date, end_date, name
from (
SELECT /*+ leading(t) */ sum(leads) leads, 0 opportunities, start_date, end_date, name
FROM (
SELECT leads, time_id, period_type_id, update_time_id,update_period_type_id
FROM BIM_I_LP_GEN_SG_MV a, eni_denorm_hierarchies edh,mtl_default_category_sets mtl
WHERE a.group_id(+) IN (:l_group_id)
AND a.product_category_id = edh.child_id AND edh.object_type = ''CATEGORY_SET'' AND edh.object_id = mtl.category_set_id AND mtl.functional_area_id = 11 AND edh.dbi_flag = ''Y'' AND edh.parent_id = &ITEM+ENI_ITEM_VBH_CAT
AND a.resource_id(+) =:l_resource_id
) a,
(SELECT * FROM (
SELECT id time_id, start_date, end_date, value name
FROM '||l_table_name||'
WHERE end_date < trunc(&BIS_PREVIOUS_ASOF_DATE)
ORDER BY start_date DESC
) t where rownum <= :l_row_count -1) t
WHERE a.time_id(+) = t.time_id
AND a.period_type_id(+) = :l_period_type
AND a.update_time_id(+) =-1
AND a.update_period_type_id(+) =-1
group by name,start_date, end_date
UNION ALL /*Opportunity*/
SELECT /*+ leading(t) */ 0 leads, sum(cnv_opty_amt) opportunities, start_date, end_date, name
from (
select cnv_opty_amt'||l_curr_suffix||' cnv_opty_amt, effective_time_id, effective_period_type_id
FROM BIL_BI_OPTY_PG_MV a, eni_denorm_hierarchies edh,mtl_default_category_sets mtl
WHERE a.parent_sales_group_id(+) = :l_group_id
AND a.product_category_id = edh.child_id AND edh.object_type = ''CATEGORY_SET'' AND edh.object_id = mtl.category_set_id AND mtl.functional_area_id = 11 AND edh.dbi_flag = ''Y'' AND edh.parent_id = &ITEM+ENI_ITEM_VBH_CAT
AND a.salesrep_id(+) = :l_resource_id
) a,
(SELECT * FROM (
SELECT id time_id, start_date, end_date, value name
FROM '||l_table_name||'
WHERE end_date < trunc(&BIS_PREVIOUS_ASOF_DATE)
ORDER BY start_date DESC
) t where rownum <= :l_row_count -1) t
WHERE a.effective_time_id(+) = t.time_id
AND a.effective_period_type_id(+) = :l_period_type
group by name,start_date, end_date
) group by start_date, end_date, name
UNION ALL /*Leads*/
SELECT sum(leads) leads, sum(opportunities) opportunities, start_date, end_date, name
from (
SELECT leads, opportunities, start_date, end_date, name
FROM (SELECT * FROM (SELECT id time_id, start_date, end_date, value name,
trunc(&BIS_PREVIOUS_ASOF_DATE) report_date
FROM '||l_table_name||'
WHERE start_date <= trunc(&BIS_PREVIOUS_ASOF_DATE)
AND end_date >= trunc(&BIS_PREVIOUS_ASOF_DATE)
ORDER BY start_date desc
) t WHERE rownum <= 1
) t,
(SELECT /*+ leading(c) */ SUM(NVL(a.leads,0)) leads, 0 opportunities, report_date
FROM
(SELECT report_date, time_id, period_type_id
FROM FII_TIME_RPT_STRUCT
WHERE calendar_id = -1
AND report_date = trunc(&BIS_PREVIOUS_ASOF_DATE)
AND BITAND(record_type_id,:l_record_type) = record_type_id
) c,
( SELECT leads, time_id, period_type_id, update_time_id,update_period_type_id
FROM BIM_I_LP_GEN_SG_MV a, eni_denorm_hierarchies edh,mtl_default_category_sets mtl
WHERE a.group_id IN ( :l_group_id )
AND a.product_category_id = edh.child_id AND edh.object_type = ''CATEGORY_SET'' AND edh.object_id = mtl.category_set_id AND mtl.functional_area_id = 11 AND edh.dbi_flag = ''Y'' AND edh.parent_id = &ITEM+ENI_ITEM_VBH_CAT
AND a.resource_id = :l_resource_id
) a
WHERE a.time_id = c.time_id
AND a.period_type_id = c.period_type_id
AND a.update_time_id =-1
AND a.update_period_type_id =-1
GROUP BY report_date
) b WHERE t.report_date = b.report_date(+)
UNION ALL /*Opportunity*/
SELECT leads, opportunities, start_date, end_date, name
FROM (SELECT * FROM (SELECT id time_id, start_date, end_date, value name,
trunc(&BIS_PREVIOUS_ASOF_DATE) report_date
FROM '||l_table_name||'
WHERE start_date <= trunc(&BIS_PREVIOUS_ASOF_DATE)
AND end_date >= trunc(&BIS_PREVIOUS_ASOF_DATE)
ORDER BY start_date desc
) t WHERE rownum <= 1
) t,
(SELECT /*+ leading(c) */ 0 leads, SUM(NVL(a.cnv_opty_amt,0)) opportunities, report_date
FROM
(SELECT report_date, time_id, period_type_id
FROM FII_TIME_RPT_STRUCT
WHERE calendar_id = -1
AND report_date = trunc(&BIS_PREVIOUS_ASOF_DATE)
AND BITAND(record_type_id,:l_record_type) = record_type_id
) c,
(select cnv_opty_amt'||l_curr_suffix||' cnv_opty_amt, effective_time_id, effective_period_type_id
FROM BIL_BI_OPTY_PG_MV a, eni_denorm_hierarchies edh,mtl_default_category_sets mtl
WHERE a.parent_sales_group_id = :l_group_id
AND a.product_category_id = edh.child_id AND edh.object_type = ''CATEGORY_SET'' AND edh.object_id = mtl.category_set_id AND mtl.functional_area_id = 11 AND edh.dbi_flag = ''Y'' AND edh.parent_id = &ITEM+ENI_ITEM_VBH_CAT
AND a.salesrep_id = :l_resource_id
) a
WHERE a.effective_time_id = c.time_id
AND a.effective_period_type_id = c.period_type_id
GROUP BY report_date) b
WHERE t.report_date = b.report_date(+)
) group by start_date, end_date, name
ORDER BY start_date)
group by start_date, end_date, name, rownum) b
WHERE a.sequence = b.sequence(+)
group by a.name,b.start_date
order by b.start_date';
l_select_grp varchar2(20000);
l_select_srep varchar2(20000);
l_top_sql := 'SELECT viewby, VIEWBYID ,leads_new BIM_ATTRIBUTE3,curr_open BIM_ATTRIBUTE2,rank_a BIM_ATTRIBUTE4,
(curr_total-curr_leads_changed) BIM_ATTRIBUTE6, DECODE(curr_open,0,0,((curr_total-curr_leads_changed)/curr_open)*100) BIM_ATTRIBUTE7,
leads_dead BIM_ATTRIBUTE9,leads_closed BIM_ATTRIBUTE10,
leads_converted BIM_ATTRIBUTE12,
DECODE((prior_open+leads_new),0,NULL,(leads_converted/(prior_open+leads_new))*100) BIM_ATTRIBUTE13,DECODE(leads_converted,0,NULL,conversion_time/leads_converted) BIM_ATTRIBUTE14,'
|| l_url_sg ||' BIM_URL1,'||l_url_camp||' BIM_URL2,
SUM(leads_new) OVER() BIM_GRAND_TOTAL2, SUM(curr_open) OVER() BIM_GRAND_TOTAL1,SUM(rank_a) OVER() BIM_GRAND_TOTAL3,
SUM(curr_total-curr_leads_changed) OVER() BIM_GRAND_TOTAL4,
DECODE(SUM(curr_open) OVER(),0,0,(SUM(curr_total-curr_leads_changed) OVER()/SUM(curr_open) OVER())*100) BIM_GRAND_TOTAL5,
SUM(leads_closed) OVER() BIM_GRAND_TOTAL7, SUM(leads_dead) OVER() BIM_GRAND_TOTAL6,
SUM(leads_converted) OVER() BIM_GRAND_TOTAL8, ((SUM(leads_converted) OVER())*100)/(sum(NVL(prior_open,0)+NVL(leads_new,0)) OVER()) BIM_GRAND_TOTAL9,
DECODE(sum(leads_converted) over(),0,NULL,sum(conversion_time) over()/sum(leads_converted) over()) BIM_GRAND_TOTAL10
FROM ( select viewby, viewbyid'||l_object_type||' ,is_resource,
sum(prior_open) prior_open, sum(curr_open) curr_open,
sum(curr_total) curr_total, sum(leads_converted) leads_converted,
sum(leads_new) leads_new,sum(rank_a) rank_a, sum(leads_dead) leads_dead,
sum(leads_closed) leads_closed, sum(curr_leads_changed) curr_leads_changed,
sum(conversion_time) conversion_time FROM (';
l_select_grp := ' SELECT '||l_grp_name0||',is_resource,prior_open,curr_open,curr_total,leads_converted,leads_new,rank_a,leads_dead,
leads_closed,curr_leads_changed,conversion_time from ( Select b.group_id VIEWBYID,0 is_resource,'||l_comm_col1||l_from||l_denorm ||l_where||l_where_grp||
' AND BITAND(c.record_type_id,1143)=c.record_type_id AND c.report_date in (&BIS_CURRENT_ASOF_DATE,&BIS_CURRENT_EFFECTIVE_START_DATE - 1) and resource_id = :l_resource_id GROUP BY b.group_id UNION ALL
Select b.group_id VIEWBYID,0 is_resource,'||l_comm_col2||l_from||l_denorm||l_where||l_where_grp||' AND BITAND(c.record_type_id,:l_record_type)=c.record_type_id AND c.report_date = &BIS_CURRENT_ASOF_DATE
and resource_id = :l_resource_id GROUP BY b.group_id) q, '||l_grp_join0;
l_select_srep:= ' SELECT '||l_srep_name1||l_object_type||',is_resource,prior_open,curr_open,curr_total,leads_converted,leads_new,rank_a,leads_dead,
leads_closed,curr_leads_changed,conversion_time from ( select '||l_srep_col_i||' VIEWBYID,1 is_resource,'||l_comm_col1||l_from||l_where||'
AND BITAND(c.record_type_id,1143)=c.record_type_id AND c.report_date in (&BIS_CURRENT_ASOF_DATE,&BIS_CURRENT_EFFECTIVE_START_DATE - 1)'||l_where_res||'
and b.group_id=:l_group_id GROUP BY '||l_srep_col_i||' union all select '||l_srep_col_i||' VIEWBYID, 1 is_resource,'||l_comm_col2||l_from||l_where||'
AND BITAND(c.record_type_id,:l_record_type)=c.record_type_id AND c.report_date =&BIS_CURRENT_ASOF_DATE' ||l_where_res||' and b.group_id=:l_group_id GROUP BY '||l_srep_col_i||' ) q ,'||l_srep_join1;
l_query:=l_top_sql||l_select_grp||' UNION ALL '||l_select_srep||l_filter_sql;
l_query:=l_top_sql||l_select_srep||l_filter_sql;
select to_char(LAST_REFRESH_DATE,'DD/MM/YYYY') FROM BIS_OBJ_PROPERTIES WHERE OBJECT_NAME = mv_name
AND OBJECT_TYPE='MV';
l_where :=' WHERE gdn.group_id=:l_group_id and delete_flag=''N''
and gdn.group_id = a.group_id
and a.resource_id=:l_resource_id and a.resource_id=gdn .resource_id';
l_qry:= ' select to_char(A.lead_id) BIM_ATTRIBUTE1,
a.lead_name BIM_ATTRIBUTE2,
a.customer_id customer_id,
a.cust_category cust_category,
a.source_code_id source_code_id,
a.lead_rank_id lead_rank_id,
a.channel_code channel_code,
to_char(a.LEAD_CREATION_DATE) BIM_ATTRIBUTE8
, '||''''||l_lead_url_str||''''||'||A.lead_id BIM_URL1 ';
l_cls_resn_qry:= ' select cls.MEANING,null,bim_pmv_dbi_utl_pkg.get_lookup_value('||''''||'UNA'||''''||')'||',cls.MEANING) BIM_ATTRIBUTE1
,count(a.lead_id) BIM_ATTRIBUTE2,avg(a.lead_closed_date-lead_creation_date) BIM_ATTRIBUTE3,
'||''''||l_url_str||'''||a.close_reason||''&BIM_PARAMETER8=''||decode(cls.MEANING,null,bim_pmv_dbi_utl_pkg.get_lookup_value('||''''||'UNA'||''''||')'||',cls.MEANING) BIM_URL1
-- '||''''||l_url_str||''''||''||'||decode(cls.MEANING,null,bim_pmv_dbi_utl_pkg.get_lookup_value('||''''||'UNA'||''''||')'||',cls.MEANING)'||'||'||''''||'&BIM_PARAMETER9=''||a.close_reason BIM_URL1
,SUM(count(a.lead_id)) OVER() BIM_GRAND_TOTAL1, sum(avg(a.lead_closed_date-lead_creation_date)*count(a.lead_id)) OVER()/SUM(count(a.lead_id)) OVER() BIM_GRAND_TOTAL2';
l_outer_query := ' SELECT BIM_ATTRIBUTE1,BIM_ATTRIBUTE2,
(SELECT party_name FROM hz_parties WHERE party_id = INNER.customer_id) BIM_ATTRIBUTE3,
(SELECT customer_category_name from bic_cust_category_v c where c.customer_category_code = inner.cust_category ) BIM_ATTRIBUTE4,
(SELECT name FROM bim_i_obj_name_mv WHERE source_code_id = INNER.source_code_id AND language = userenv(''LANG'')) BIM_ATTRIBUTE5,
(SELECT r.meaning FROM as_sales_lead_ranks_vl r WHERE r.rank_id = inner.lead_rank_id ) BIM_ATTRIBUTE6,
(SELECT s.meaning FROM so_lookups s WHERE s.lookup_type(+) = ''SALES_CHANNEL'' and s.lookup_code = inner.CHANNEL_CODE ) BIM_ATTRIBUTE7,
BIM_ATTRIBUTE8,BIM_URL1, ';
l_outer_query:= l_outer_query|| '(SELECT W.MEANING FROM as_statuses_tl w ,as_statuses_b w1 WHERE w.status_code=w1.status_code and w.language=userenv(''LANG'') and w1.lead_flag=''Y'' and w1.status_code=inner.lead_status) BIM_ATTRIBUTE9,
BIM_ATTRIBUTE10 from ( ';
l_outer_query:= l_outer_query|| '((SELECT W.MEANING FROM as_statuses_tl w ,as_statuses_b w1 WHERE w.status_code=w1.status_code and w.language=userenv(''LANG'') and w1.lead_flag=''Y'' and w1.status_code=inner.lead_status) BIM_ATTRIBUTE9,
BIM_ATTRIBUTE10 from ( ';
select to_char(LAST_REFRESH_DATE,'DD/MM/YYYY') FROM BIS_OBJ_PROPERTIES WHERE OBJECT_NAME = mv_name
AND OBJECT_TYPE='MV';
l_where :=' WHERE gdn.group_id=:l_group_id and delete_flag=''N''
and gdn.group_id = a.group_id
and a.resource_id=:l_resource_id and a.resource_id=gdn .resource_id';
l_qry:= ' select A.lead_id BIM_ATTRIBUTE1,
a.lead_name BIM_ATTRIBUTE2,
a.customer_id customer_id,
a.cust_category cust_category,
a.source_code_id source_code_id,
a.lead_rank_id lead_rank_id,
a.channel_code channel_code,
a.LEAD_CREATION_DATE BIM_ATTRIBUTE8
, '||''''||l_lead_url_str||''''||'||A.lead_id BIM_URL1 ';
l_cls_resn_qry:= ' select cls.value BIM_ATTRIBUTE1
,count(a.lead_id) BIM_ATTRIBUTE2,avg(a.lead_closed_date-lead_creation_date) BIM_ATTRIBUTE3,
decode(a.close_reason,null,null,'||''''||l_url_str||'''||a.close_reason||''&BIM_PARAMETER8=''||cls.value) BIM_URL1
-- '||''''||l_url_str||''''||''||'||decode(cls.MEANING,null,bim_pmv_dbi_utl_pkg.get_lookup_value('||''''||'UNA'||''''||')'||',cls.MEANING)'||'||'||''''||'&BIM_PARAMETER9=''||a.close_reason BIM_URL1
,SUM(count(a.lead_id)) OVER() BIM_GRAND_TOTAL1, sum(avg(a.lead_closed_date-lead_creation_date)*count(a.lead_id)) OVER()/SUM(count(a.lead_id)) OVER() BIM_GRAND_TOTAL2';
and NVL(a.lead_rank_id,-999) not in ( SELECT OBJECT_DEF FROM BIM_R_CODE_DEFINITIONS WHERE object_type = ''RANK_DBI'' AND column_name IN (''A'',''B'',''C'',''D''))';
l_outer_query := ' SELECT BIM_ATTRIBUTE1,BIM_ATTRIBUTE2,
(SELECT party_name FROM hz_parties WHERE party_id = INNER.customer_id) BIM_ATTRIBUTE3,
(SELECT value FROM bim_i_attr_name_mv WHERE UMARK=''CCUST'' AND id = INNER.cust_category and LANGUAGE=userenv(''LANG'')) BIM_ATTRIBUTE4,
(SELECT name FROM bim_i_obj_name_mv WHERE source_code_id = INNER.source_code_id AND language = userenv(''LANG'')) BIM_ATTRIBUTE5,
(SELECT value FROM bim_i_attr_name_mv WHERE UMARK=''RANK'' AND id = INNER.lead_rank_id and LANGUAGE=userenv(''LANG'')) BIM_ATTRIBUTE6,
(SELECT value FROM bim_i_attr_name_mv WHERE UMARK=''CHANNEL'' AND id = INNER.CHANNEL_CODE and LANGUAGE=userenv(''LANG'')) BIM_ATTRIBUTE7,
BIM_ATTRIBUTE8,BIM_URL1, ';
l_outer_query:= l_outer_query|| '(SELECT value FROM bim_i_attr_name_mv WHERE UMARK=''STATUS'' AND id = lead_status and LANGUAGE=userenv(''LANG'')) BIM_ATTRIBUTE9,BIM_ATTRIBUTE10 from ( ';
l_outer_query:= l_outer_query|| '(SELECT value FROM bim_i_attr_name_mv WHERE UMARK=''STATUS'' AND id = lead_status and LANGUAGE=userenv(''LANG'')) BIM_ATTRIBUTE9,BIM_ATTRIBUTE10 from ( ';
RETURN 'select 1 BIM_MEASURE1 from dual where 1=2';
UPDATE BIS_USER_ATTRIBUTES
SET SESSION_VALUE = '''100000148''', SESSION_DESCRIPTION = '* LELLISON'
WHERE function_name = 'BIM_I_LEAD_MGMT_PARAM_PORTLET'
AND attribute_name ='ORGANIZATION+JTF_ORG_SALES_GROUP';