select

mtrh.request_number                  发货单号,
       mmt.transaction_date                  发货时间,
       oola.creation_date                       下单时间,
       nvl(fu.description, fu.user_name) 下单人员,
       ott.name                                    订单类型,
       qp.name                                       价目表,
       srp.name                                   销售人员,
       a.acra1                                      销售大区,
       a.acra2                                         办事处,
       cust_acct.account_number          客户编码,
       hp.party_name                           客户名称,
       ship_su.location                         发货地址,
       ship_loc.address1                       客户地址,
       ooha.order_number                 销售订单号,
       oola.line_number                       订单行号,
       oola.ordered_item                      产品型号,
       msib.segment1                          物料编码,
       msib.description                        物料描述,
       msib.primary_unit_of_measure        单位,
       ooha.transactional_curr_code     订单币种,
       oola.unit_selling_price                     价格,
       mmt.transaction_quantity          发货数量,
       round(mmt.transaction_quantity * oola.unit_selling_price, 2) 发货金额,
       nvl((select gdr.conversion_rate
             from gl.gl_daily_rates gdr
            where gdr.conversion_type = 'Corporate'
              and gdr.from_currency = ooha.transactional_curr_code
              and trunc(gdr.conversion_date) = trunc(ooha.creation_date)
              and gdr.from_currency <> 'CNY'), 1) 汇率,
       nvl((select gdr.conversion_rate
             from gl.gl_daily_rates gdr
            where gdr.conversion_type = 'Corporate'
              and gdr.from_currency = ooha.transactional_curr_code
              and trunc(gdr.conversion_date) = trunc(ooha.creation_date)
              and gdr.from_currency <> 'CNY'), 1) * oola.unit_selling_price "价格CNY",
       round(nvl((select gdr.conversion_rate
                   from gl.gl_daily_rates gdr
                  where gdr.conversion_type = 'Corporate'
                    and gdr.from_currency = ooha.transactional_curr_code
                    and trunc(gdr.conversion_date) =
                        trunc(ooha.creation_date)
                    and gdr.from_currency <> 'CNY'), 1) *
             mmt.transaction_quantity * oola.unit_selling_price, 2) "发货金额CNY",
       rt.name                                    付款条件,
       mtrl.date_required               交付通知时间,
       wdd.shipping_instructions          发运说明
  from wsh.wsh_delivery_details              wdd,
       inv.mtl_txn_request_lines                mtrl,
       inv.mtl_txn_request_headers          mtrh,
       ont.oe_order_lines_all                     oola,
       ont.oe_order_headers_all               ooha,
       ont.oe_transaction_types_tl               ott,
       jtf.jtf_rs_salesreps                            srp,
       ar.hz_parties                                     hp,
       ar.hz_party_sites                              hps,
       ar.hz_cust_accounts cust_acct,
       ar.hz_cust_site_uses_all ship_su,
       ar.hz_locations ship_loc,
       ar.hz_cust_acct_sites_all ship_cas,
       inv.mtl_system_items_b msib,
       inv.mtl_material_transactions mmt,
       applsys.fnd_user fu,
       qp.qp_list_headers_tl qp,
       ar.ra_terms_tl rt,
       (select ffv1.flex_value acra1,
               ffv2.flex_value acra2,
               hc.site_use_id
          from ar.ra_territories        rt,
               apps.fnd_flex_values_vl  ffv1,
               apps.fnd_flex_values_vl  ffv2,
               ar.hz_cust_site_uses_all hc
         where ffv1.flex_value_set_id = 1014164
           and ffv2.flex_value_set_id = 1014165
           and rt.segment1 = ffv1.flex_value(+)
           and rt.segment2 = ffv2.flex_value(+)
           and hc.site_use_code = 'BILL_TO'
           and rt.territory_id = hc.territory_id) a
 where mtrl.header_id = mtrh.header_id
   and ooha.sold_to_org_id = cust_acct.cust_account_id(+)
   and cust_acct.party_id = hp.party_id(+)
   and ooha.ship_to_org_id = ship_su.site_use_id(+)
   and ship_su.cust_acct_site_id = ship_cas.cust_acct_site_id(+)
   and ship_cas.party_site_id = hps.party_site_id(+)
   and ship_loc.location_id(+) = hps.location_id
   and mtrl.line_id = wdd.move_order_line_id
   and wdd.source_line_id = oola.line_id
   and wdd.source_header_id = oola.header_id
   and oola.inventory_item_id = msib.inventory_item_id(+)
   and oola.ship_from_org_id = msib.organization_id(+)
   and ooha.order_type_id = ott.transaction_type_id
   and oola.header_id = ooha.header_id
   and ooha.salesrep_id = srp.salesrep_id(+)
   and ooha.org_id = srp.org_id(+)
   and mmt.move_order_line_id = mtrl.line_id
   and wdd.organization_id = mmt.organization_id
   and wdd.inventory_item_id = mmt.inventory_item_id
   and wdd.inventory_item_id = msib.inventory_item_id
   and mmt.transaction_type_id = 52 --33
   and mmt.transaction_quantity > 0
   and ott.language = userenv('LANG')
   and wdd.source_code = 'OE'
   and wdd.released_status in ('C', 'Y')
   and oola.org_id = x
   and msib.organization_id = y
   and a.site_use_id(+) = ooha.invoice_to_org_id
   and fu.user_id = ooha.created_by
   and qp.list_header_id = ooha.price_list_id
   and qp.language = userenv('LANG')
   and rt.term_id = oola.payment_term_id
   and rt.language = 'ZHS'
union all ----增加退货部分
select '' 发货单号,
       mmt.transaction_date                  发货时间,
       oola.creation_date                       下单时间,
       nvl(fu.description, fu.user_name) 下单人员,
       ott.name                                    订单类型,
       qp.name                                       价目表,
       srp.name                                   销售人员,
       a.acra1                                      销售大区,
       a.acra2                                         办事处,
       cust_acct.account_number          客户编码,
       hp.party_name                           客户名称,
       ship_su.location                         发货地址,
       ship_loc.address1                      客户地址,
       ooha.order_number                销售订单号,
       oola.line_number                      订单行号,
       oola.ordered_item                     产品型号,
       msib.segment1                         物料编码,
       msib.description                        物料描述,
       msib.primary_unit_of_measure        单位,
       ooha.transactional_curr_code    订单币种,
       oola.unit_selling_price                    价格,
       -round(mmt.transaction_quantity, 4) 发货数量,
       -round(mmt.transaction_quantity * oola.unit_selling_price, 2) 发货金额,
       nvl((select gdr.conversion_rate
             from gl.gl_daily_rates gdr
            where gdr.conversion_type = 'Corporate'
              and gdr.from_currency = ooha.transactional_curr_code
              and trunc(gdr.conversion_date) = trunc(ooha.creation_date)
              and gdr.from_currency <> 'CNY'), 1) 汇率,
       nvl((select gdr.conversion_rate
             from gl.gl_daily_rates gdr
            where gdr.conversion_type = 'Corporate'
              and gdr.from_currency = ooha.transactional_curr_code
              and trunc(gdr.conversion_date) = trunc(ooha.creation_date)
              and gdr.from_currency <> 'CNY'), 1) * oola.unit_selling_price "价格CNY",
       -round(nvl((select gdr.conversion_rate
                   from gl.gl_daily_rates gdr
                  where gdr.conversion_type = 'Corporate'
                    and gdr.from_currency = ooha.transactional_curr_code
                    and trunc(gdr.conversion_date) =
                        trunc(ooha.creation_date)
                    and gdr.from_currency <> 'CNY'), 1) *
             mmt.transaction_quantity * oola.unit_selling_price, 2) "发货金额CNY",
       rt.name                                  付款条件,
       mmt.transaction_date        交付通知时间,
       ' ' 发运说明
  from ont.oe_order_lines_all                oola,
       ont.oe_order_headers_all             ooha,
       ont.oe_transaction_types_tl            ott,
       jtf.jtf_rs_salesreps                         srp,
       ar.hz_parties                                  hp,
       ar.hz_party_sites                          hps,
       ar.hz_cust_accounts cust_acct,
       ar.hz_cust_site_uses_all ship_su,
       ar.hz_locations ship_loc,
       ar.hz_cust_acct_sites_all ship_cas,
       inv.mtl_system_items_b msib,
       inv.mtl_material_transactions mmt,
       po.rcv_transactions rt,
       applsys.fnd_user fu,
       qp.qp_list_headers_tl qp,
       ar.ra_terms_tl rt,
       (select ffv1.flex_value acra1,
               ffv2.flex_value acra2,
               hc.site_use_id
          from ar.ra_territories        rt,
               apps.fnd_flex_values_vl  ffv1,
               apps.fnd_flex_values_vl  ffv2,
               ar.hz_cust_site_uses_all hc
         where ffv1.flex_value_set_id = 1014164
           and ffv2.flex_value_set_id = 1014165
           and rt.segment1 = ffv1.flex_value(+)
           and rt.segment2 = ffv2.flex_value(+)
           and hc.site_use_code = 'BILL_TO'
           and rt.territory_id = hc.territory_id) a
 where ooha.sold_to_org_id = cust_acct.cust_account_id(+)
   and cust_acct.party_id = hp.party_id(+)
   and ooha.ship_to_org_id = ship_su.site_use_id(+)
   and ship_su.cust_acct_site_id = ship_cas.cust_acct_site_id(+)
   and ship_cas.party_site_id = hps.party_site_id(+)
   and ship_loc.location_id(+) = hps.location_id
   and oola.inventory_item_id = msib.inventory_item_id(+)
   and oola.ship_from_org_id = msib.organization_id(+)
   and oola.line_category_code = 'RETURN'
   and ooha.order_type_id = ott.transaction_type_id
   and oola.header_id = ooha.header_id
   and ooha.salesrep_id = srp.salesrep_id(+)
   and ooha.org_id = srp.org_id(+)
   and mmt.transaction_type_id = 15
   and mmt.rcv_transaction_id = rt.transaction_id
   and mmt.organization_id = rt.organization_id
   and rt.oe_order_header_id = ooha.header_id
   and rt.oe_order_line_id = oola.line_id
   and ott.language = userenv('LANG')
   and msib.organization_id = y
   and a.site_use_id(+) = ooha.invoice_to_org_id
   and fu.user_id = ooha.created_by
   and qp.list_header_id = ooha.price_list_id
   and qp.language = userenv('LANG')
   and rt.term_id = oola.payment_term_id
   and rt.language = 'ZHS'
union all ----直接开票订单
select to_char('') 发货单号,
       oola.fulfillment_date                    发货时间,
       oola.creation_date                       下单时间,
       nvl(fu.description, fu.user_name)  下单人员,
       ott.name                                     订单类型,
       qp.name                                        价目表,
       srp.name                                     销售人员,
       a.acra1                                        销售大区,
       a.acra2                                           办事处,
       cust_acct.account_number            客户编码,
       hp.party_name                             客户名称,
       ship_su.location                            发货地址,
       ship_loc.address1                         客户地址,
       ooha.order_number                   销售订单号,
       oola.line_number                          订单行号,
       oola.ordered_item                         产品型号,
       msib.segment1                              物料编码,
       msib.description                             物料描述,
       msib.primary_unit_of_measure             单位,
       ooha.transactional_curr_code          订单币种,
       oola.unit_selling_price                          价格,
       round(oola.fulfilled_quantity, 2)       发货数量,
       round(oola.fulfilled_quantity * oola.unit_selling_price, 2) 发货金额,
       nvl((select gdr.conversion_rate
             from gl.gl_daily_rates gdr
            where gdr.conversion_type = 'Corporate'
              and gdr.from_currency = ooha.transactional_curr_code
              and trunc(gdr.conversion_date) = trunc(ooha.creation_date)
              and gdr.from_currency <> 'CNY'), 1) 汇率,
       nvl((select gdr.conversion_rate
             from gl.gl_daily_rates gdr
            where gdr.conversion_type = 'Corporate'
              and gdr.from_currency = ooha.transactional_curr_code
              and trunc(gdr.conversion_date) = trunc(ooha.creation_date)
              and gdr.from_currency <> 'CNY'), 1) * oola.unit_selling_price "价格CNY",
       round(nvl((select gdr.conversion_rate
                   from gl.gl_daily_rates gdr
                  where gdr.conversion_type = 'Corporate'
                    and gdr.from_currency = ooha.transactional_curr_code
                    and trunc(gdr.conversion_date) =
                        trunc(ooha.creation_date)
                    and gdr.from_currency <> 'CNY'), 1) *
             oola.fulfilled_quantity * oola.unit_selling_price, 2) "发货金额CNY",
       rt.name                                   付款条件,
       oola.fulfillment_date           交付通知时间,
       ' ' 发运说明
  from ont.oe_order_lines_all                 oola,
       ont.oe_order_headers_all              ooha,
       ont.oe_transaction_types_tl              ott,
       jtf.jtf_rs_salesreps                           srp,
       ar.hz_parties                                    hp,
       ar.hz_party_sites                            hps,
       ar.hz_cust_accounts cust_acct,
       ar.hz_cust_site_uses_all ship_su,
       ar.hz_locations ship_loc,
       ar.hz_cust_acct_sites_all ship_cas,
       inv.mtl_system_items_b msib,
       applsys.fnd_user fu,
       qp.qp_list_headers_tl qp,
       ar.ra_terms_tl rt,
       ( select ffv1.flex_value acra1,
                  ffv2.flex_value acra2,
                  hc.site_use_id
          from ar.ra_territories        rt,
                  apps.fnd_flex_values_vl  ffv1,
                  apps.fnd_flex_values_vl  ffv2,
                  ar.hz_cust_site_uses_all hc
         where ffv1.flex_value_set_id = 1014164
           and ffv2.flex_value_set_id = 1014165
           and rt.segment1 = ffv1.flex_value(+)
           and rt.segment2 = ffv2.flex_value(+)
           and hc.site_use_code = 'BILL_TO'
           and rt.territory_id = hc.territory_id) a
 where ooha.sold_to_org_id = cust_acct.cust_account_id(+)
   and cust_acct.party_id = hp.party_id(+)
   and ooha.ship_to_org_id = ship_su.site_use_id(+)
   and ship_su.cust_acct_site_id = ship_cas.cust_acct_site_id(+)
   and ship_cas.party_site_id = hps.party_site_id(+)
   and ship_loc.location_id(+) = hps.location_id
   and oola.inventory_item_id = msib.inventory_item_id(+)
   and oola.ship_from_org_id = msib.organization_id(+)
   and ooha.order_type_id = ott.transaction_type_id
   and oola.header_id = ooha.header_id
   and ooha.salesrep_id = srp.salesrep_id(+)
   and ooha.org_id = srp.org_id(+)
   and oola.flow_status_code = 'CLOSED'
   and oola.inventory_item_id = msib.inventory_item_id
   and oola.ship_from_org_id = msib.organization_id
   and ott.language = userenv('LANG')
   and oola.line_category_code <> 'RETURN'
   and oola.org_id = x
   and msib.organization_id = y
   and a.site_use_id(+) = ooha.invoice_to_org_id
   and fu.user_id = ooha.created_by
   and qp.list_header_id = ooha.price_list_id
   and qp.language = userenv('LANG')
   and rt.term_id = oola.payment_term_id
   and rt.language = 'ZHS'
   and not exists (select 'X'
          from wsh.wsh_delivery_details wdd
         where wdd.source_header_id = oola.header_id
           and wdd.source_line_id = oola.line_id)

Oracle EBS-SQL (OM-1):查询订单发货明细.sql的更多相关文章

  1. Oracle和MySql的分页查询区别和PL/SQL的基本概念

    Oracle和MySql的分页查询区别:     Oracle的分析查询,之前Oracle的分页是使用伪列 ROWNUM 结合子查询实现,mysql的分页更简单,直接使用 LIMIT 关键字就可以实现 ...

  2. ORACLE EBS常用表及查询语句(最终整理版)

    建议去看参考二 参考一:                                                              call fnd_global.APPS_INITI ...

  3. Oracle EBS-SQL (PO-9):检查期间采购订单执行情况.sql

    --采购订单执行情况查询(七天内接收情况)select pha.segment1       采购订单,         msib.segment1      物料编码,         pla.qu ...

  4. Oracle EBS 跳跳转标准销售订单程序转标准销售订单程序

    -- 打开PO PROCEDURE Btn_Open_Po IS BEGIN Fnd_Function.Execute(Function_Name => 'PO_POXPOEPO', Open_ ...

  5. SQL SERVER中查询无主键的SQL

    --生成表 IF  EXISTS ( SELECT  name                FROM    sysobjects                WHERE   xtype = 'u' ...

  6. JAVAEE——Mybatis第二天:输入和输出映射、动态sql、关联查询、Mybatis整合spring、Mybatis逆向工程

    1. 学习计划 1.输入映射和输出映射 a) 输入参数映射 b) 返回值映射 2.动态sql a) If标签 b) Where标签 c) Sql片段 d) Foreach标签 3.关联查询 a) 一对 ...

  7. 《Entity Framework 6 Recipes》中文翻译系列 (13) -----第三章 查询之使用Entity SQL

    翻译的初衷以及为什么选择<Entity Framework 6 Recipes>来学习,请看本系列开篇 3-4使用实体SQL查询模型 问题 你想通过执行Entity SQL语句来查询你的实 ...

  8. Python与开源GIS:在OGR中使用SQL语句进行查询

    摘要: 属性选择与空间选择都可以看作是OGR内置的选择功能,这两种功能可以解决大部分实际中的问题.但是也有这种时候,就是进行查询时的条件比较复杂.针对这种情况,OGR也提供了更加灵活的解决方案:支持使 ...

  9. oracle SQL多表查询

    SQL多表查询 1.集合理论 1.1 什么是集合 具有某种特定性质的事物的总体. 集合的特性:无序性.互异性.确定性. 一个集合可以小到从一个表中取出一行中的一列.              1 ro ...

随机推荐

  1. Android自学学习资料

    最近在自学Android编程,在网上看了一些博客和视频教程,觉得比较好的分享一下,继续学习,gangbade~ 国外android官网总是出现连不上的情况,如果你不想FQ的话,这里github上可以直 ...

  2. 段(SEGMENT)

    伪指令SEGMENT被用来声明一个普通段.一个再定位类型(relocation type)和一个地址分配类型(allocation type)可以按如下形式指明: segment SEGMENT cl ...

  3. mysql服务的注册,启动、停止、注销。 [delphi代码实现]

    unit Service; interface uses Windows,Classes,SysUtils,Winsvc,winsock; Type {服务句柄信息} TScmInfo=Record ...

  4. Json之语法,格式

    JSON 文本格式在语法上与创建 JavaScript 对象的代码相同.由于这种相似性,无需解析器,JavaScript 程序能够使用内建的 eval() 函数,用 JSON 数据来生成原生的 Jav ...

  5. Android Studio 调试过程中快捷查看断点处变量值(Ctrl+Shift+I无效)?

    当你在做Keymap到Eclipse后,在debug过程中,在Eclipse中我们很喜欢用Ctrl+Shift+I去查看一个运算或者调用的结果,这样用起来很方便.但是keymap到Eclipse后,你 ...

  6. case then 的用法 貌似case then不支持别名

    set ANSI_NULLS ONset QUOTED_IDENTIFIER ONgo ALTER PROC [dbo].[usp_SRV_GetALLRelativeProject]@Service ...

  7. UESTC_基爷的中位数 2015 UESTC Training for Search Algorithm & String<Problem D>

    D - 基爷的中位数 Time Limit: 5000/3000MS (Java/Others)     Memory Limit: 65535/65535KB (Java/Others) Submi ...

  8. 【剑指offer】面试题23:从上往下打印二叉树

    题目: 从上往下打印出二叉树的每个节点,同层节点从左至右打印. 思路: bfs,队列. 注意,队列最后不要忘了pop(). 代码: /* struct TreeNode { int val; stru ...

  9. OpenCV MFC 模块间通信

    1. 新建MFC项目 点击完成. 2. 添加按钮 在"工具箱"中找到"Button"控件,添加至界面:  2. 配置opencv, 添加colordetecto ...

  10. SQL 通配符

    在搜索数据库中的数据时,SQL 通配符可以替代一个或多个字符.SQL 通配符必须与 LIKE 运算符一起使用,必须放在引号内. 在 SQL 中,可使用以下通配符: %:替代一个或多个字符. _:仅替代 ...