Wednesday, October 10, 2012

Tax Report Query

SELECT to_char(SI.creation_date, 'dd-mon-rr')   "F01" -- Cr_Date
              , SI.SEGMENT1                              "F02" -- SKU
              , SI.DESCRIPTION                           "F03" -- Description
              , substr(CT.segment3, 1, 6)                "F04" -- Dept
              , substr(CT.segment4, 1, 6)                "F05" -- Cat
              , SI.inventory_item_status_code            "F06" -- COFI_St
              , SI.tax_code                              "F07" -- Tax_Code
              , DV.element_value                         "F08" -- Desc_Value
              , SI.item_type                             "F09" -- Item_Type 
         FROM   mtl_system_items_B         SI
              , mtl_descr_element_values   DE
              , apps.mtl_categories        CT
              , mtl_item_categories        IC
              , mtl_descr_element_values   EV
              , mtl_descr_element_values   DV
         WHERE  1 = 1
         AND    DE.inventory_item_id          = SI.inventory_item_id
         AND    SI.organization_id            = 22
         AND    SI.inventory_item_status_code in ('COFI Activ', 'EOL', 'Disc')
         AND    (SI.tax_code is NULL or
                 SI.tax_code NOT IN('200801ESRGSTPST','200802ESRGSTPST','200802ESRCOMBOGSTPST'))
         --AND    upper(SI.item_type)='WTY'       
         AND    DE.element_name               = 'Description'
         AND    IC.inventory_item_id          = SI.inventory_item_id
         AND    IC.organization_id            = SI.organization_id
         AND    IC.category_set_id            = 1
         AND    CT.category_id                = IC.category_id
         AND    CT.segment3                   = 627           -- Appliances only ! --
         AND    EV.inventory_item_id          = SI.inventory_item_id
         AND    EV.element_name               = 'Energy Star'
         AND    EV.element_value              = 'Yes'
         AND    DV.inventory_item_id          = SI.inventory_item_id
         AND    DV.element_sequence           = 10
    UNION        
    --To Include TG Sku's which requires an update in tax_code 
         select to_char(SI.creation_date, 'dd-mon-rr')   "F01" -- Cr_Date
          ,SI.segment1                                   "F02" -- SKU
          ,SI.description                                "F03" -- Description
          ,substr(CT.segment3,1,6)                       "F04" -- Dept
          ,substr(CT.segment4,1,6)                       "F05" -- Cat
          ,SI.inventory_item_status_code                 "F06" -- COFI_St
          ,SI.tax_code                                   "F07" -- Tax_Code
           ,EV.element_value                             "F08" -- Desc_Value
          ,SI.item_type                                  "F09" -- Item_Type 
    from mtl_system_items_b  SI
    , MTL_ITEM_CATEGORIES IC
    , mtl_categories_b CT
    ,mtl_descr_element_values EV
    where
    SI.inventory_item_id = IC.inventory_item_id
    and SI.organization_id = IC.organization_id
    and IC.category_id = CT.category_id
    and SI.organization_id = 22
    and CT.SEGMENT1 <> '47'
    and CT.segment1 <> 'DEFAULT_CONTRACT'
    and SI.segment1 not like '%-%'
    and CT.segment1 not like 'MI%'
    and CT.segment4 <> '47'
    and SI.PRIMARY_UNIT_OF_MEASURE not in ('EACH', 'BOX', 'Minute')
    and SI.INVENTORY_ITEM_STATUS_CODE in ('COFI Activ', 'EOL', 'Disc')
    and SI.list_price_per_unit is not null
    and (tax_code is NULL
    or tax_code <>'200907TGGSTPST')
    and EV.inventory_item_id = SI.inventory_item_id
    and EV.element_sequence = 10

Output:

No comments:

Post a Comment