銷售單-請購單-採購單連接SQL

select distinct oh.order_number ,prh.segment1 as "請購單", 
prl.line_num 請購單行號,
v.vendor_name 供應商,
L.description 收貨地點,
poh.segment1  購進單號,
pol.line_num  購進行號,
ol.line_number 銷售訂單行號, it.segment1 EBS料號, it.description
       , OL.ORDERED_QUANTITY-nvl(OL.ATTRIBUTE13,0)  as "需申請採購數量"
         ,OL.ORDERED_QUANTITY  as "銷售數量"
        , ol.flow_status_code 訂單狀態
       ,oh.attribute2 as "用戶"
       ,oh.attribute7 as "收貨人"
       ,oh.attribute8 as "電話"
       ,oh.attribute6 as "詳細地址"
      --       , c1.SEGMENT1||','|| c1.SEGMENT2||','|| c1.SEGMENT2||','|| c1.SEGMENT4  as "C1"
       --, c1.description as "基本分類"
      --, c2.SEGMENT1 as "C2"
       , c2.description as "管理分類"
       , it.ATTRIBUTE2 as "供應商貨號" , it.ATTRIBUTE3 as "U9碼", xiu_util_pkg.GET_FLEX_DESC('XIU_BRAND_CATERGORIES', it.ATTRIBUTE15 ) as "品牌"
   ,prl.cancel_flag
   ,PRL.CLOSED_CODE   
   ,prh.segment1 
   from oe_order_lines_all ol
      , mtl_system_items_b it
      , oe_order_headers_all oh
/*      , mtl_item_categories  ic1
      , mtl_categories_vl    c1*/
      , mtl_item_categories  ic2
      , mtl_categories_vl    c2
      , po_requisition_lines_all  prl
      ,po_requisition_headers_all prh
      , po_line_locations_all ploc
      , po_lines_all pol
      , po_headers_all poh
      ,ap_suppliers v  
      ,HR_LOCATIONS L   
     
   where ol.ordered_item = it.segment1
   and   ol.header_id = oh.header_id
   and  it.organization_id = 81
   and  it.item_type= 0
/*   and  ic1.inventory_item_id = it.inventory_item_id
   and  ic1.organization_id = it.organization_id
   and  ic1.category_set_id = 1
   and  c1.category_id = ic1.category_id*/
   and  ic2.inventory_item_id = it.inventory_item_id
   and  ic2.organization_id = it.organization_id
   and  ic2.category_set_id = 1100000041
   and  c2.category_id = ic2.category_id
   and prl.requisition_header_id=prh.requisition_header_id
   and prl.attribute2 =ol.line_id
   and prl.vendor_id=v.vendor_id(+)
   and PRL.DELIVER_TO_LOCATION_ID=L.location_id(+)
   and ol.flow_status_code not in('CANCELLED')
   and TO_NUMBER(prh.SEGMENT1)>12  
   and prl.cancel_flag  <>'Y' 
   and prl.line_location_id = ploc.line_location_id (+) 
   and ploc.po_line_id = pol.po_line_id (+) 
   and pol.po_header_id = poh.po_header_id (+) 




發佈了1 篇原創文章 · 獲贊 3 · 訪問量 4萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章