items.description,
(SELECT b.reporting_code
FROM apps.jai_item_templ_hdr_v a,
apps.jai_reporting_associations_v b
WHERE b.entity_id = a.template_hdr_id
AND b.effective_from IS NOT NULL
AND b.effective_to IS NULL
AND b.regime_code = 'IND GST'
AND b.reporting_type_code = 'GST_HSN_CODE'
AND a.inventory_item_id = items.inventory_item_id
AND ROWNUM = 1) hsn_code,
qlh.name price_list_name,
Nvl (qpl.operand, 0) list_price,
cat.segment1,
cat.segment2
FROM apps.mtl_system_items_b items,
apps.qp_pricing_attributes price_attrs,
apps.qp_list_lines qpl,
apps.mtl_item_categories_v cat,
apps.qp_secu_list_headers_v qlh
WHERE items.organization_id = <<ITEM_MASTER_ORGANIZATION_ID>>
AND items.inventory_item_id = cat.inventory_item_id(+)
AND items.organization_id = cat.organization_id(+)
AND price_attrs.list_header_id = qlh.list_header_id
AND cat.category_set_name(+) = 'CNS_MIS_CAT'
AND price_attrs.product_attribute_context = 'ITEM'
AND price_attrs.product_attribute = 'PRICING_ATTRIBUTE1'
AND qlh.name = <<PRICE_LIST_NAME>>
AND price_attrs.product_attr_value = To_char (items.inventory_item_id)
AND price_attrs.list_line_id = qpl.list_line_id
AND qpl.end_date_active IS NULL;
If we need to include items with last END_DATE_ACTIVE then
SELECT items.segment1 item_code,-- qpl.LIST_LINE_ID,
items.description,
qpl.end_date_active,
(SELECT b.reporting_code
FROM apps.jai_item_templ_hdr_v a,
apps.jai_reporting_associations_v b
WHERE b.entity_id = a.template_hdr_id
AND b.effective_from IS NOT NULL
AND b.effective_to IS NULL
AND b.regime_code = 'IND GST'
AND b.reporting_type_code = 'GST_HSN_CODE'
AND a.inventory_item_id = items.inventory_item_id
AND ROWNUM = 1) hsn_code,
qlh.name price_list_name,
Nvl (qpl.operand, 0) list_price,
cat.segment1 MIS_CAT_SEG1,
cat.segment2 MIS_CAT_SEG2
FROM apps.mtl_system_items_b items,
apps.qp_pricing_attributes price_attrs,
apps.qp_list_lines qpl,
apps.mtl_item_categories_v cat,
apps.qp_secu_list_headers_v qlh
WHERE items.organization_id = 112
AND items.inventory_item_id = cat.inventory_item_id(+)
AND items.organization_id = cat.organization_id(+)
AND price_attrs.list_header_id = qlh.list_header_id
AND cat.category_set_name(+) = 'CNS_MIS_CAT'
AND price_attrs.product_attribute_context = 'ITEM'
AND price_attrs.product_attribute = 'PRICING_ATTRIBUTE1'
AND qlh.name = <<PRICE_LIST_NAME>>
AND price_attrs.product_attr_value = To_char (items.inventory_item_id)
AND price_attrs.list_line_id = qpl.list_line_id
--and items.segment1 = <
AND Nvl(qpl.end_date_active, To_date('9/9/9999', 'mm/dd/yyyy')) =
(SELECT Max(Nvl(qpl1.end_date_active, To_date('9/9/9999', 'mm/dd/yyyy')))
FROM apps.qp_pricing_attributes price_attrs1,
apps.qp_list_lines qpl1
WHERE 1 = 1
AND price_attrs1.list_header_id = qlh.list_header_id
AND price_attrs1.list_line_id = qpl1.list_line_id
AND price_attrs1.product_attribute_context = 'ITEM'
AND price_attrs1.product_attribute = 'PRICING_ATTRIBUTE1'
AND price_attrs1.product_attr_value = price_attrs.product_attr_value );