Вы находитесь на странице: 1из 16

create or replace VIEW "busobj_group".

"OLUS_Usage_Detail_View"
(
Date_Time_Ordered,
Date_Time_Fulfilled,
Requestor_ID,
Reference_ID,
Company_Inquired,
Inquery_City,
Inquery_State,
Inquery_Country,
Inquery_Duns_Nbr,
Taxed,
Offer,
Subscriber,
Usage_Type,
International_YN,
Usage_Product_Type,
Usg_Stmt_Seq,
Period_Begin_Dt,
Period_End_Dt,
Product_Code,
prcg_pref_cd,
Product_Name,
How_Accessed_Delivered,
Quantity,
Cost_at_List,
Discounted_Cost,
Metered,
Access_System_Code,
Delivery_Method_Code,
subr_usr_eml_adr,
Layer,
Product_Name_French
)
AS

SELECT
to_date(to_char( u.DATE_TIME_ORDERED, 'MM/DD/YYYY HH:MI:SS ' ) +
substring(TRIM(Upper(convert(varchar,u.DATE_TIME_ORDERED))),char_length(trim(Upper(
convert(varchar,u.DATE_TIME_ORDERED))))-1,2),'MM/DD/YYYY HH:MI:SS ')
DATE_TIME_ORDERED,
-- convert(varchar,u.DATE_TIME_ORDERED,100) DATE_TIME_ORDERED,
to_date(to_char( u.DATE_TIME_FULFILLED, 'MM/DD/YYYY HH:MI:SS ' ) +
substring(TRIM(Upper(convert(varchar,u.DATE_TIME_FULFILLED))),char_length(trim(Uppe
r(convert(varchar,u.DATE_TIME_FULFILLED))))-1,2),'MM/DD/YYYY HH:MI:SS ')
DATE_TIME_FULFILLED,
isnull(u.opid,0) opid,
case when endorsement is null or endorsement = 'NULL' then ' ' else
endorsement end as endorsement,
isnull(u.case_name,' ') case_name,
isnull(u.case_city,' ') case_city,
isnull(u.case_state_province,' ') case_state_province,
isnull(u.case_country,' ') case_country,
isnull(u.Case_Duns_Nbr,0) Case_Duns_Nbr,
isnull(u.taxed_YN,'N') taxed_YN,
u.offer_seq,
u.subr_nbr,
case
when u.prfd_part_prcg_elgb_indc='0' then
'Ineligible'
else
'Elligible'
end as usage_type,

case
when Product.intl_indc='1' then
'Y'
else
'N'
end as International_YN,
case
when u.prfd_part_prcg_elgb_indc='0' then
'Additional'
else
case
when Product.intl_indc='1' then
case when o.template_type_code in
('1120035','1120036','1120037','1120038','1120135','1120136','1120137','1120138')
then
'Included'
else
'International'
end
else
'Included'
end
end as usage_product_type,

s.usage_stmt_seq,
s.period_begin_date,
s.period_end_date,
Product.product_code,
Product.prcg_pref_cd,
rtrim(Product.product_name ) product_name,
--defect # 48
'' How_Accessed_Delivered,

Case
when Product.prcg_pref_cd = '1510003' then
0
else
sum(u.quantity)
end as quantity,
sum(u.list_price * u.quantity) cost_at_list,
sum(u.price_for_balance * u.quantity) discounted_cost,
Case
when Product.prcg_pref_cd = '1510003' then
'N'
else
'Y'
end as Metered,
U.Access_System_Code,
U.Delivery_Method_Code,
isnull(U.subr_usr_eml_adr,'') subr_usr_eml_adr,
'' Layer,
rtrim(Product.product_name) product_name_french
FROM
(select distinct p.product_code,
isnull(BPHMN.prod_hier_mbr_nme,p.product_name) product_name, p.prcg_pref_cd,
p.intl_indc , isnull(BPHMN.lang_cd,'E') lang_cd from
busobj_group.bolt_product p left outer join
busobj_group.BOLT_prod_hier_mbr BPHM on (p.product_code= BPHM.prod_cd)
left outer join busobj_group.BOLT_prod_hier_mbr_nme BPHMN on
(BPHM.prod_hier_mbr_id = BPHMN.prod_hier_mbr_id)) Product,
-- busobj_group.bolt_product Product,
busobj_group.bolt_usage_stmt s right outer Join
busobj_group.bolt_inq_det_assoc a ON ( s.usage_stmt_seq = a.usage_stmt_seq) right
outer join
busobj_group.IQ_north_amer_usage_rec u ON ( a.bolt_btr_seq =
u.bolt_btr_seq) left outer Join busobj_group.bolt_offer o ON ( o.offer_seq =
u.offer_seq)

WHERE
--Below conditions for capturing closed period usage.
u.product_code = Product.product_code
AND (u.DATE_TIME_ORDERED <= (Select isnull(max(date(period_End_date)),date('2010-
01-01')) from busobj_group.bolt_usage_stmt where offer_seq = u.offer_seq)
AND u.entry_date <= (Select isnull(max(date(period_End_date)),date('2010-01-01'))
from busobj_group.bolt_usage_stmt where offer_seq = u.offer_seq))
AND Product.prcg_pref_cd IN ('1510002', '1510003', '1510004') -- get metered,
unmetered and inelligible
AND o.template_type_code IN ('1120039', '1120040', '1120041', '1120042',
'1120043', '1120044', '1120139', '1120140', '1120141', '1120142', '1120143',
'1120144','1120045','1120047','1120046','1120145','1120147','1120146')
AND u.product_code <> 'CREDITWITHTAX'
AND Product.lang_cd='E'
and u.subr_nbr = s.subr_nbr
and s.PERIOD_BEGIN_DATE > DATEADD(MM, -30, GETDATE())
and o.effective_date > DATEADD(MM, -30, GETDATE()) -- This condition for NON
MDPs only.
GROUP BY
u.DATE_TIME_ORDERED,u.DATE_TIME_FULFILLED,u.opid,u.endorsement,u.case_name,u.case_c
ity,u.case_state_province, u.case_country,u.Case_Duns_Nbr,u.taxed_YN,u.offer_seq,
u.subr_nbr,
u.prfd_part_prcg_elgb_indc,
Product.intl_indc,
Product.prcg_pref_cd,
s.usage_stmt_seq,
s.period_begin_date,
s.period_end_date,
Product.product_code,
How_Accessed_Delivered,
o.template_type_code ,
rtrim(Product.product_name ),
Metered,
U.Access_System_Code,
U.Delivery_Method_Code,
U.subr_usr_eml_adr,
Layer,
product_name_french

UNION ALL
SELECT
to_date(to_char( u.DATE_TIME_ORDERED, 'MM/DD/YYYY HH:MI:SS ' ) +
substring(TRIM(Upper(convert(varchar,u.DATE_TIME_ORDERED))),char_length(trim(Upper(
convert(varchar,u.DATE_TIME_ORDERED))))-1,2),'MM/DD/YYYY HH:MI:SS ')
DATE_TIME_ORDERED,
-- convert(varchar,u.DATE_TIME_ORDERED,100) DATE_TIME_ORDERED,
to_date(to_char( u.DATE_TIME_FULFILLED, 'MM/DD/YYYY HH:MI:SS ' ) +
substring(TRIM(Upper(convert(varchar,u.DATE_TIME_FULFILLED))),char_length(trim(Uppe
r(convert(varchar,u.DATE_TIME_FULFILLED))))-1,2),'MM/DD/YYYY HH:MI:SS ')
DATE_TIME_FULFILLED,
isnull(u.opid,0) opid,
case when endorsement is null or endorsement = 'NULL' then ' ' else
endorsement end as endorsement,
isnull(u.case_name,' ') case_name,
isnull(u.case_city,' ') case_city,
isnull(u.case_state_province,' ') case_state_province,
isnull(u.case_country,' ') case_country,
isnull(u.Case_Duns_Nbr,0) Case_Duns_Nbr,
isnull(u.taxed_YN,'N') taxed_YN,
u.offer_seq,
u.subr_nbr,
case
when u.prfd_part_prcg_elgb_indc='0' then
'Ineligible'
else
'Elligible'
end as usage_type,

case
when Product.intl_indc='1' then
'Y'
else
'N'
end as International_YN,
case
when u.prfd_part_prcg_elgb_indc='0' then
'Additional'
else
case
when Product.intl_indc='1' then
case when o.template_type_code in
('1120009','1120020','1120010','1120004','1120104','1120035', '1120036', '1120037',
'1120038', '1120135', '1120136', '1120137', '1120138') then
'Included'
else
'International'
end
else
'Included'
end
end as usage_product_type,

s.usage_stmt_seq,
s.period_begin_date,
s.period_end_date,
Product.product_code,
Product.prcg_pref_cd,
rtrim(Product.product_name ) Product_Name,
'' How_Accessed_Delivered,
Case
when Product.prcg_pref_cd = '1510003' then
--May need to add condition for DNBi 2011 contract to make refresh
count as 0
sum(u.quantity)
else
sum(u.quantity)
end as quantity,
sum(u.list_price * u.quantity) cost_at_list,
case when (u.overrun_yn = 'Y' and u.prfd_part_prcg_elgb_indc <> '0' and
o.template_type_code IN ('1120029', '1120030', '1120032', '1120031', '1120034',
'1120035', '1120036', '1120037', '1120038','1120129', '1120130', '1120132',
'1120131', '1120134', '1120135', '1120136', '1120137', '1120138') ) then
case
when Product.intl_indc='1' then
case when o.template_type_code in
('1120009','1120020','1120004','1120010','1120104','1120001','1120007','1120013','1
120021','1120022','1120101','1120107') then
0
else
sum(u.price_for_balance * u.quantity)
end
else
sum(u.price_for_balance * u.quantity)
end
else
sum(u.price_for_balance * u.quantity)
end as discounted_cost,
'Y' Metered,
U.Access_System_Code,
U.Delivery_Method_Code,
isnull(U.subr_usr_eml_adr,'') subr_usr_eml_adr,
'' Layer,
rtrim(Product.product_name) product_name_french

FROM

(select distinct p.product_code,


isnull(BPHMN.prod_hier_mbr_nme,p.product_name) product_name, p.prcg_pref_cd,
p.intl_indc , isnull(BPHMN.lang_cd,'E') lang_cd from
busobj_group.bolt_product p left outer join
busobj_group.BOLT_prod_hier_mbr BPHM on (p.product_code= BPHM.prod_cd)
left outer join busobj_group.BOLT_prod_hier_mbr_nme BPHMN on
(BPHM.prod_hier_mbr_id = BPHMN.prod_hier_mbr_id)) Product,
-- busobj_group.bolt_product Product,
busobj_group.bolt_usage_stmt s right outer Join
busobj_group.bolt_inq_det_assoc a ON ( s.usage_stmt_seq = a.usage_stmt_seq) right
outer join
busobj_group.IQ_north_amer_usage_rec u ON ( a.bolt_btr_seq =
u.bolt_btr_seq) left outer Join busobj_group.bolt_offer o ON ( o.offer_seq =
u.offer_seq)

WHERE
--Below conditions for capturing closed period usage.
u.product_code = Product.product_code
AND (u.DATE_TIME_ORDERED <= (Select isnull(max(date(period_End_date)),date('2010-
01-01')) from busobj_group.bolt_usage_stmt where offer_seq = u.offer_seq)
AND u.entry_date <= (Select isnull(max(date(period_End_date)),date('2010-01-01'))
from busobj_group.bolt_usage_stmt where offer_seq = u.offer_seq))
AND u.product_code <> 'CREDITWITHTAX'
AND Product.lang_cd='E'
AND o.template_type_code NOT IN
('1120002','1120008','1120011','1120012','1120102','1120108','1120005','1120105',
'1120039', '1120040', '1120041', '1120042', '1120043', '1120044', '1120139',
'1120140', '1120141', '1120142', '1120143', '1120144',

'1120014','1120015','1120016','1120017','1120018','1120019','1120023','1120024','11
20025','1120026','1120027','1120028','1120033',
'1120115','1120117','1120118','1120119','1120123','1120045','1120047','1120046','11
20145','1120147','1120146' )
and u.subr_nbr = s.subr_nbr
and s.PERIOD_BEGIN_DATE > DATEADD(MM, -30, GETDATE())
and o.effective_date > DATEADD(MM, -30, GETDATE())

GROUP BY
u.DATE_TIME_ORDERED,u.DATE_TIME_FULFILLED,u.opid,u.endorsement,u.case_name,u.case_c
ity,u.case_state_province, u.case_country,u.Case_Duns_Nbr,u.taxed_YN,u.offer_seq,
u.subr_nbr,
u.prfd_part_prcg_elgb_indc,
Product.intl_indc,
s.usage_stmt_seq,
s.period_begin_date,
s.period_end_date,
Product.product_code,
Product.prcg_pref_cd,
How_Accessed_Delivered,
o.template_type_code,
rtrim(Product.product_name ),
u.overrun_yn,
Metered,
U.Access_System_Code,
U.Delivery_Method_Code,
U.subr_usr_eml_adr,
Layer,
product_name_french

UNION ALL

SELECT
to_date(to_char( u.DATE_TIME_ORDERED, 'MM/DD/YYYY HH:MI:SS ' ) +
substring(TRIM(Upper(convert(varchar,u.DATE_TIME_ORDERED))),char_length(trim(Upper(
convert(varchar,u.DATE_TIME_ORDERED))))-1,2),'MM/DD/YYYY HH:MI:SS ')
DATE_TIME_ORDERED,
-- convert(varchar,u.DATE_TIME_ORDERED,100) DATE_TIME_ORDERED,
to_date(to_char( u.DATE_TIME_FULFILLED, 'MM/DD/YYYY HH:MI:SS ' ) +
substring(TRIM(Upper(convert(varchar,u.DATE_TIME_FULFILLED))),char_length(trim(Uppe
r(convert(varchar,u.DATE_TIME_FULFILLED))))-1,2),'MM/DD/YYYY HH:MI:SS ')
DATE_TIME_FULFILLED,
isnull(u.opid,0) opid,
case when endorsement is null or endorsement = 'NULL' then ' ' else
endorsement end as endorsement,
isnull(u.case_name,' ') case_name,
isnull(u.case_city,' ') case_city,
isnull(u.case_state_province,' ') case_state_province,
isnull(u.case_country,' ') case_country,
isnull(u.Case_Duns_Nbr,0) Case_Duns_Nbr,
isnull(u.taxed_YN,'N') taxed_YN,
u.offer_seq,
u.subr_nbr,
case
when u.prfd_part_prcg_elgb_indc='0' then
'Ineligible'
else
'Elligible'
end as usage_type,

case
when Product.intl_indc='1' then
'Y'
else
'N'
end as International_YN,
case
when u.prfd_part_prcg_elgb_indc='0' then
'Additional'
else
case
when Product.intl_indc='1' then
case when o.template_type_code in
('1120009','1120020','1120004','1120010','1120104','1120001','1120007','1120013','1
120021','1120022','1120101','1120107','1120035', '1120036', '1120037', '1120038',
'1120135', '1120136', '1120137', '1120138') then
'Included'
else
'International'
end
else
'Included'
end
end as usage_product_type,

0 usage_stmt_seq,
null period_begin_date,
null period_end_date,
Product.product_code,
Product.prcg_pref_cd,
rtrim(Product.product_name ) Product_Name,
'' How_Accessed_Delivered,

Case
when Product.prcg_pref_cd = '1510003' then
--May need to add condition for DNBi 2011 contract to make refresh
count as 0
sum(u.quantity)
else
sum(u.quantity)
end as quantity,
sum(u.list_price * u.quantity) cost_at_list,
case when (u.overrun_yn = 'Y' and u.prfd_part_prcg_elgb_indc <> '0' and
o.template_type_code IN ('1120029', '1120030', '1120032', '1120031', '1120034',
'1120035', '1120036', '1120037', '1120038','1120129', '1120130', '1120132',
'1120131', '1120134', '1120135', '1120136', '1120137', '1120138') ) then
case
when Product.intl_indc='1' then
case when o.template_type_code in
('1120009','1120020','1120004','1120010','1120104','1120001','1120007','1120013','1
120021','1120022','1120101','1120107') then
0
else
sum(u.price_for_balance * u.quantity)
end
else
sum(u.price_for_balance * u.quantity)
end
else
sum(u.price_for_balance * u.quantity)
end as discounted_cost,
'Y' Metered,
U.Access_System_Code,
U.Delivery_Method_Code,
isnull(U.subr_usr_eml_adr,'') subr_usr_eml_adr,
'' Layer,
rtrim(Product.product_name) product_name_french

FROM

(select distinct p.product_code,


isnull(BPHMN.prod_hier_mbr_nme,p.product_name) product_name, p.prcg_pref_cd,
p.intl_indc , isnull(BPHMN.lang_cd,'E') lang_cd from
busobj_group.bolt_product p left outer join
busobj_group.BOLT_prod_hier_mbr BPHM on (p.product_code= BPHM.prod_cd)
left outer join busobj_group.BOLT_prod_hier_mbr_nme BPHMN on
(BPHM.prod_hier_mbr_id = BPHMN.prod_hier_mbr_id)) Product,
-- busobj_group.bolt_product Product,
busobj_group.IQ_north_amer_usage_rec u left outer Join
busobj_group.bolt_offer o ON ( o.offer_seq = u.offer_seq)

WHERE
--Below conditions for capturing current period usage.
u.product_code = Product.product_code
AND u.product_code <> 'CREDITWITHTAX'
AND Product.lang_cd='E'
AND o.template_type_code not IN
('1120002','1120008','1120011','1120012','1120102','1120108','1120005','1120105',
'1120039', '1120040', '1120041', '1120042', '1120043', '1120044', '1120139',
'1120140', '1120141', '1120142', '1120143', '1120144',

'1120014','1120015','1120016','1120017','1120018','1120019','1120023','1120024','11
20025','1120026','1120027','1120028','1120033',
'1120115','1120117','1120118','1120119','1120123','1120045','1120047','1120046','11
20145','1120147','1120146')
AND (u.DATE_TIME_ORDERED > (Select isnull(max(date(period_End_date)),date('2010-
01-01')) from busobj_group.bolt_usage_stmt where offer_seq = u.offer_seq)
OR u.entry_date > (Select isnull(max(date(period_End_date)),date('2010-01-01'))
from busobj_group.bolt_usage_stmt where offer_seq = u.offer_seq))
and o.effective_date > DATEADD(MM, -30, GETDATE())

GROUP BY u.DATE_TIME_ORDERED,u.DATE_TIME_FULFILLED,
u.opid,u.endorsement,u.case_name,u.case_city,u.case_state_province,
u.case_country,u.Case_Duns_Nbr,u.taxed_YN,u.offer_seq,
u.subr_nbr,
u.prfd_part_prcg_elgb_indc,
Product.intl_indc,
usage_stmt_seq,
period_begin_date,
period_end_date,
Product.product_code,
Product.prcg_pref_cd,
How_Accessed_Delivered,
o.template_type_code,
rtrim(Product.product_name ),
u.overrun_yn,
Metered,
U.Access_System_Code,
U.Delivery_Method_Code,
U.subr_usr_eml_adr,
Layer,
product_name_french

UNION ALL

SELECT
to_date(to_char( u.DATE_TIME_ORDERED, 'MM/DD/YYYY HH:MI:SS ' ) +
substr(TRIM(Upper(convert(varchar,u.DATE_TIME_ORDERED))),char_length(trim(Upper(con
vert(varchar,u.DATE_TIME_ORDERED))))-1,2),'MM/DD/YYYY HH:MI:SS ')
DATE_TIME_ORDERED,
-- convert(varchar,u.DATE_TIME_ORDERED,100) DATE_TIME_ORDERED,
to_date(to_char( u.DATE_TIME_FULFILLED, 'MM/DD/YYYY HH:MI:SS ' ) +
substr(TRIM(Upper(convert(varchar,u.DATE_TIME_FULFILLED))),char_length(trim(Upper(c
onvert(varchar,u.DATE_TIME_FULFILLED))))-1,2),'MM/DD/YYYY HH:MI:SS ')
DATE_TIME_FULFILLED,
isnull(u.opid,0) opid,
case when endorsement is null or endorsement = 'NULL' then ' ' else
endorsement end as endorsement,
isnull(u.case_name,' ') case_name,
isnull(u.case_city,' ') case_city,
isnull(u.case_state_province,' ') case_state_province,
isnull(u.case_country,' ') case_country,
isnull(u.Case_Duns_Nbr,0) Case_Duns_Nbr,
isnull(u.taxed_YN,'N') taxed_YN,
u.offer_seq,
u.subr_nbr,
case
when u.prfd_part_prcg_elgb_indc='0' then
'Ineligible'
else
'Elligible'
end as usage_type,

case
when Product.intl_indc='1' then
'Y'
else
'N'
end as International_YN,
case
when u.prfd_part_prcg_elgb_indc='0' then
'Additional'
else
case
when Product.intl_indc='1' then
case when o.template_type_code in
('1120035','1120036','1120037','1120038','1120135','1120136','1120137','1120138')
then
'Included'
else
'International'
end
else
'Included'
end
end as usage_product_type,

0 usage_stmt_seq,
null period_begin_date,
null period_end_date,
Product.product_code,
Product.prcg_pref_cd,
rtrim(Product.product_name ) product_name,
--defect # 48
'' How_Accessed_Delivered,
Case
when Product.prcg_pref_cd = '1510003' then
0
else
sum(u.quantity)
end as quantity,
sum(u.list_price * u.quantity) cost_at_list,
sum(u.price_for_balance * u.quantity) discounted_cost,
Case
when Product.prcg_pref_cd = '1510003' then
'N'
else
'Y'
end as Metered,
U.Access_System_Code,
U.Delivery_Method_Code,
isnull(U.subr_usr_eml_adr,'') subr_usr_eml_adr,
'' Layer,
rtrim(Product.product_name) product_name_french

FROM
(select distinct p.product_code,
isnull(BPHMN.prod_hier_mbr_nme,p.product_name) product_name, p.prcg_pref_cd,
p.intl_indc , isnull(BPHMN.lang_cd,'E') lang_cd from
busobj_group.bolt_product p left outer join
busobj_group.BOLT_prod_hier_mbr BPHM on (p.product_code= BPHM.prod_cd)
left outer join busobj_group.BOLT_prod_hier_mbr_nme BPHMN on
(BPHM.prod_hier_mbr_id = BPHMN.prod_hier_mbr_id)) Product,
-- busobj_group.bolt_product Product,
busobj_group.IQ_north_amer_usage_rec u left outer Join
busobj_group.bolt_offer o ON ( o.offer_seq = u.offer_seq)
WHERE
--Below conditions for capturing current period usage.
u.product_code = Product.product_code
AND Product.prcg_pref_cd IN ('1510002', '1510003', '1510004') -- get metered,
unmetered and inelligible
-- AND o.template_type_code IN ('1120039', '1120040', '1120041', '1120042',
'1120043', '1120044', '1120139', '1120140', '1120141', '1120142', '1120143',
'1120144')
AND o.template_type_code IN ('1120039', '1120040', '1120041', '1120042',
'1120043', '1120044', '1120139', '1120140', '1120141', '1120142', '1120143',
'1120144','1120045','1120047','1120046','1120145','1120147','1120146')
AND u.product_code <> 'CREDITWITHTAX'
AND Product.lang_cd='E'
AND (u.DATE_TIME_ORDERED > (Select isnull(max(date(period_End_date)),date('2010-
01-01')) from busobj_group.bolt_usage_stmt where offer_seq = u.offer_seq)
OR u.entry_date > (Select isnull(max(date(period_End_date)),date('2010-01-01'))
from busobj_group.bolt_usage_stmt where offer_seq = u.offer_seq))
and o.effective_date > DATEADD(MM, -30, GETDATE())

GROUP BY
u.DATE_TIME_ORDERED,u.DATE_TIME_FULFILLED,u.opid,u.endorsement,u.case_name,u.case_c
ity,u.case_state_province, u.case_country,u.Case_Duns_Nbr,u.taxed_YN,u.offer_seq,
u.subr_nbr,
u.prfd_part_prcg_elgb_indc,
Product.intl_indc,
Product.prcg_pref_cd,
usage_stmt_seq,
period_begin_date,
period_end_date,
Product.product_code,
How_Accessed_Delivered,
o.template_type_code ,
rtrim(Product.product_name ),
Metered,
U.Access_System_Code,
U.Delivery_Method_Code,
U.subr_usr_eml_adr,
Layer,
product_name_french

Union All
SELECT
to_date(to_char( u.DATE_TIME_ORDERED, 'MM/DD/YYYY HH:MI:SS ' ) +
substring(TRIM(Upper(convert(varchar,u.DATE_TIME_ORDERED))),char_length(trim(Upper(
convert(varchar,u.DATE_TIME_ORDERED))))-1,2),'MM/DD/YYYY HH:MI:SS ')
DATE_TIME_ORDERED,
-- convert(varchar,u.DATE_TIME_ORDERED,100) DATE_TIME_ORDERED,
to_date(to_char( u.DATE_TIME_FULFILLED, 'MM/DD/YYYY HH:MI:SS ' ) +
substring(TRIM(Upper(convert(varchar,u.DATE_TIME_FULFILLED))),char_length(trim(Uppe
r(convert(varchar,u.DATE_TIME_FULFILLED))))-1,2),'MM/DD/YYYY HH:MI:SS ')
DATE_TIME_FULFILLED,
isnull(u.opid,0) opid,
case when endorsement is null or endorsement = 'NULL' then ' ' else
endorsement end as endorsement,
isnull(u.case_name,' ') case_name,
isnull(u.case_city,' ') case_city,
isnull(u.case_state_province,' ') case_state_province,
isnull(u.case_country,' ') case_country,
isnull(u.Case_Duns_Nbr,0) Case_Duns_Nbr,
isnull(u.taxed_YN,'N') taxed_YN,
u.offer_seq,
u.subr_nbr,
case
when u.prfd_part_prcg_elgb_indc='0' then
'Ineligible'
else
'Elligible'
end as usage_type,

case
when Product.intl_indc='1' then
'Y'
else
'N'
end as International_YN,
case
when u.prfd_part_prcg_elgb_indc='0' then
'Additional'
else
case
when Product.intl_indc='1' then
case when o.template_type_code in
('1120009','1120020','1120004','1120010','1120104','1120001','1120007','1120013','1
120021','1120022','1120101','1120107') then
'Included'
else
'International'
end
else
'Included'
end
end as usage_product_type,

Invoice.Invoice_Usage_Seq usage_stmt_seq,
Invoice.from_date period_begin_date,
Invoice.end_date period_end_date,
Product.product_code,
Product.prcg_pref_cd,
rtrim(Product.product_name ) Product_Name,
'' How_Accessed_Delivered,

Case
when Product.prcg_pref_cd = '1510003' then
--May need to add condition for DNBi 2011 contract to make refresh
count as 0
sum(u.quantity)
else
sum(u.quantity)
end as quantity,
sum(u.list_price * u.quantity) cost_at_list,
case when (u.overrun_yn = 'Y' and u.prfd_part_prcg_elgb_indc <> '0' and
o.template_type_code IN ('1120029', '1120030', '1120032', '1120031', '1120034',
'1120035', '1120036', '1120037', '1120038','1120129', '1120130', '1120132',
'1120131', '1120134', '1120135', '1120136', '1120137', '1120138') ) then
case
when Product.intl_indc='1' then
case when o.template_type_code in
('1120009','1120020','1120004','1120010','1120104','1120001','1120007','1120013','1
120021','1120022','1120101','1120107') then
0
else
sum(u.price_for_balance * u.quantity)
end
else
sum(u.price_for_balance * u.quantity)
end
else
sum(u.price_for_balance * u.quantity)
end as discounted_cost,
'Y' Metered,
U.Access_System_Code,
U.Delivery_Method_Code,
isnull(U.subr_usr_eml_adr,'') subr_usr_eml_adr,
'' Layer,
rtrim(Product.product_name) product_name_french

FROM

(select distinct p.product_code,


isnull(BPHMN.prod_hier_mbr_nme,p.product_name) product_name, p.prcg_pref_cd,
p.intl_indc , isnull(BPHMN.lang_cd,'E') lang_cd from
busobj_group.bolt_product p left outer join
busobj_group.BOLT_prod_hier_mbr BPHM on (p.product_code= BPHM.prod_cd)
left outer join busobj_group.BOLT_prod_hier_mbr_nme BPHMN on
(BPHM.prod_hier_mbr_id = BPHMN.prod_hier_mbr_id)) Product,
-- busobj_group.bolt_product Product,
( select distinct subr_nbr,offer_seq, Invoice_Usage_Seq, from_date,end_date
from busobj_group.bolt_inv_registration ) Invoice right outer Join
busobj_group.bolt_inq_det_assoc a ON ( Invoice.Invoice_Usage_Seq = a.Invoice_Seq)
right outer join
busobj_group.IQ_north_amer_usage_rec u ON ( a.bolt_btr_seq =
u.bolt_btr_seq) left outer Join busobj_group.bolt_offer o ON ( o.offer_seq =
u.offer_seq)

WHERE
--Below conditions for capturing closed period usage.
u.product_code = Product.product_code
AND u.product_code <> 'CREDITWITHTAX'
AND Product.lang_cd='E'
AND o.template_type_code IN
('1120002','1120008','1120011','1120012','1120102','1120108','1120005','1120105')
and u.subr_nbr = Invoice.subr_nbr
and Invoice.from_date > DATEADD(MM, -30, GETDATE())

GROUP BY
u.DATE_TIME_ORDERED,u.DATE_TIME_FULFILLED,u.opid,u.endorsement,u.case_name,u.case_c
ity,u.case_state_province, u.case_country,u.Case_Duns_Nbr,u.taxed_YN,u.offer_seq,
u.subr_nbr,
u.prfd_part_prcg_elgb_indc,
Product.intl_indc,
usage_stmt_seq,
period_begin_date,
period_end_date,
Product.product_code,
Product.prcg_pref_cd,
How_Accessed_Delivered,
o.template_type_code,
rtrim(Product.product_name ),
u.overrun_yn,
Metered,
U.Access_System_Code,
U.Delivery_Method_Code,
U.subr_usr_eml_adr,
Layer,
product_name_french

UNION ALL

SELECT
to_date(to_char( u.DATE_TIME_ORDERED, 'MM/DD/YYYY HH:MI:SS ' ) +
substring(TRIM(Upper(convert(varchar,u.DATE_TIME_ORDERED))),char_length(trim(Upper(
convert(varchar,u.DATE_TIME_ORDERED))))-1,2),'MM/DD/YYYY HH:MI:SS ')
DATE_TIME_ORDERED,
-- convert(varchar,u.DATE_TIME_ORDERED,100) DATE_TIME_ORDERED,
to_date(to_char( u.DATE_TIME_FULFILLED, 'MM/DD/YYYY HH:MI:SS ' ) +
substring(TRIM(Upper(convert(varchar,u.DATE_TIME_FULFILLED))),char_length(trim(Uppe
r(convert(varchar,u.DATE_TIME_FULFILLED))))-1,2),'MM/DD/YYYY HH:MI:SS ')
DATE_TIME_FULFILLED,
isnull(u.opid,0) opid,
case when endorsement is null or endorsement = 'NULL' then ' ' else
endorsement end as endorsement,
isnull(u.case_name,' ') case_name,
isnull(u.case_city,' ') case_city,
isnull(u.case_state_province,' ') case_state_province,
isnull(u.case_country,' ') case_country,
isnull(u.Case_Duns_Nbr,0) Case_Duns_Nbr,
isnull(u.taxed_YN,'N') taxed_YN,
u.offer_seq,
u.subr_nbr,
case
when u.prfd_part_prcg_elgb_indc='0' then
'Ineligible'
else
'Elligible'
end as usage_type,

case
when Product.intl_indc='1' then
'Y'
else
'N'
end as International_YN,
case
when u.prfd_part_prcg_elgb_indc='0' then
'Additional'
else
case
when Product.intl_indc='1' then
case when o.template_type_code in
('1120009','1120020','1120004','1120010','1120104','1120001','1120007','1120013','1
120021','1120022','1120101','1120107') then
'Included'
else
'International'
end
else
'Included'
end
end as usage_product_type,

0 usage_stmt_seq,
null period_begin_date,
null period_end_date,
Product.product_code,
Product.prcg_pref_cd,
rtrim(Product.product_name ) Product_Name,
'' How_Accessed_Delivered,

Case
when Product.prcg_pref_cd = '1510003' then
--May need to add condition for DNBi 2011 contract to make refresh
count as 0
sum(u.quantity)
else
sum(u.quantity)
end as quantity,
sum(u.list_price * u.quantity) cost_at_list,
case when (u.overrun_yn = 'Y' and u.prfd_part_prcg_elgb_indc <> '0' and
o.template_type_code IN ('1120029', '1120030', '1120032', '1120031', '1120034',
'1120035', '1120036', '1120037', '1120038','1120129', '1120130', '1120132',
'1120131', '1120134', '1120135', '1120136', '1120137', '1120138') ) then
case
when Product.intl_indc='1' then
case when o.template_type_code in
('1120009','1120020','1120004','1120010','1120104','1120001','1120007','1120013','1
120021','1120022','1120101','1120107') then
0
else
sum(u.price_for_balance * u.quantity)
end
else
sum(u.price_for_balance * u.quantity)
end
else
sum(u.price_for_balance * u.quantity)
end as discounted_cost,
'Y' Metered,
U.Access_System_Code,
U.Delivery_Method_Code,
isnull(U.subr_usr_eml_adr,'') subr_usr_eml_adr,
'' Layer,
rtrim(Product.product_name) product_name_french

FROM

(select distinct p.product_code,


isnull(BPHMN.prod_hier_mbr_nme,p.product_name) product_name, p.prcg_pref_cd,
p.intl_indc , isnull(BPHMN.lang_cd,'E') lang_cd from
busobj_group.bolt_product p left outer join
busobj_group.BOLT_prod_hier_mbr BPHM on (p.product_code= BPHM.prod_cd)
left outer join busobj_group.BOLT_prod_hier_mbr_nme BPHMN on
(BPHM.prod_hier_mbr_id = BPHMN.prod_hier_mbr_id)) Product,
-- busobj_group.bolt_product Product,
busobj_group.IQ_north_amer_usage_rec u left outer Join
busobj_group.bolt_offer o ON ( o.offer_seq = u.offer_seq)

WHERE
--Below conditions for capturing current period usage.
u.product_code = Product.product_code
AND u.product_code <> 'CREDITWITHTAX'
AND Product.lang_cd='E'
AND o.template_type_code IN
('1120002','1120008','1120011','1120012','1120102','1120108','1120005','1120105')
AND (u.DATE_TIME_ORDERED > (Select isnull(max(date(end_date)),date('2010-01-01'))
from busobj_group.bolt_inv_registration where offer_seq = u.offer_seq)
OR u.entry_date > (Select isnull(max(date(end_date)),date('2010-01-01')) from
busobj_group.bolt_inv_registration where offer_seq = u.offer_seq))

GROUP BY u.DATE_TIME_ORDERED,u.DATE_TIME_FULFILLED,
u.opid,u.endorsement,u.case_name,u.case_city,u.case_state_province,
u.case_country,u.Case_Duns_Nbr,u.taxed_YN,u.offer_seq,
u.subr_nbr,
u.prfd_part_prcg_elgb_indc,
Product.intl_indc,
usage_stmt_seq,
period_begin_date,
period_end_date,
Product.product_code,
Product.prcg_pref_cd,
How_Accessed_Delivered,
o.template_type_code,
rtrim(Product.product_name ),
u.overrun_yn,
Metered,
U.Access_System_Code,
U.Delivery_Method_Code,
U.subr_usr_eml_adr,
Layer,
product_name_french

Вам также может понравиться