with Table As QueryTable用法及实例

常用的语法结构为:

With T1 AS (QueryTable:查询语句),

T2 AS (QueryTable:查询语句),

……

Tn AS (QueryTable:查询语句)

+ QueryTable :表集合

其中:QueryTable表示select 语法结构,返回一个数据集

用法实例:

WITH T1 AS
(SELECT SPAP_TYPE,GEND_NAME,SPAP_CUST,SPAP_DATE,CM_SORT,SPAP_NBR,SPAPD_LINE,SPAPD_PART,PT_DESC1,SPAPD_QTY,SO_NBR
 FROM SPAP_MSTR
 LEFT JOIN SPAPD_DET ON SPAP_NBR=SPAPD_NBR
 LEFT JOIN CM_MSTR ON CM_ADDR=SPAP_CUST
 LEFT JOIN SO_MSTR ON SPAPD_SOD_NBR=SO_NBR
 LEFT JOIN GEND_DET ON GEND_OPTION=SPAP_TYPE AND GEND_GEN=‘BJ_TYPE‘
 LEFT JOIN PT_MSTR ON PT_PART=SPAPD_PART
 WHERE 1=1 AND SPAP_PST=1
 UNION ALL
 SELECT SPAP_TYPE,B.GEND_NAME,SO_CUST,SO_ORD_DATE,CM_SORT,SO_NBR,SOD_LINE,SOD_PART,PT_DESC1,SOD_QTY_ORD,SO_NBR
  FROM SO_MSTR
  LEFT JOIN SOD_DET ON SO_NBR=SOD_NBR
  LEFT JOIN SPAP_MSTR ON SPAP_NBR=SO_FC_NBR
  LEFT JOIN CM_MSTR ON CM_ADDR=SO_CUST
  LEFT JOIN GEND_DET B ON B.GEND_GEN=‘BJ_TYPE‘ AND B.GEND_OPTION=SPAP_TYPE AND B.GEND_DISABLED=0
  LEFT JOIN PT_MSTR ON PT_PART=SOD_PART
  WHERE SO_PST=1
  AND SO_PROG_CODE=‘SLSOMTA3‘
 )
,--售后申请单
T2 AS
(SELECT MOVD_MOV,MOVD_LINE MOVD_LINE1,MOVD_SRC_LINE MOVD_SRC_LINE1,MOVD_SRC_NBR,MOVD_QTY,MOV_PST
 FROM MOVD_DET
 LEFT JOIN MOV_MSTR ON MOVD_MOV=MOV_MOV
 WHERE 1=1
 and MOV_PROG_CODE=‘SHSBMTA1‘
 )
,--领料单
T3 AS
(SELECT MOVD_MOV,MOVD_LINE MOVD_LINE2,MOVD_SRC_LINE MOVD_SRC_LINE2,MOVD_SRC_NBR,MOVD_QTY,MOV_PST
 FROM MOV_MSTR
 LEFT JOIN MOVD_DET ON MOVD_MOV=MOV_MOV WHERE MOV_PROG_CODE=‘SHSBMTA2‘
 )
,--入库单
T4 AS
(SELECT RPLD_NBR,RPLD_LINE,RPLD_SRC_NBR,RPLD_SRC_LINE,RPLD_QTY,RPL_PST
 FROM RPL_MSTR LEFT JOIN RPLD_DET ON RPL_NBR=RPLD_NBR WHERE RPL_PROG_CODE=‘SHSBMTA4‘)
,--退料单
T5 AS
(SELECT DND_DN,DND_LINE,DND_DNA_LINE,DND_DNA,DND_QTY_SHIP,DN_PST
 FROM DN_MSTR LEFT JOIN DND_DET ON DN_DN=DND_DN WHERE DN_PROG_CODE=‘SHSBMTA3‘)
,--出库单
T6 AS
(SELECT RPLD_NBR,RPLD_LINE,RPLD_SRC_NBR,RPLD_SRC_LINE,RPLD_QTY,RPL_PST
 FROM RPL_MSTR
 LEFT JOIN RPLD_DET ON RPL_NBR=RPLD_NBR
 WHERE RPL_PROG_CODE=‘SHSBMTA5‘) --返厂单
SELECT DISTINCT T1.SPAP_TYPE,
        T1.GEND_NAME,
        T1.SPAP_CUST,
        T1.CM_SORT,
        T1.SPAP_NBR,
        T1.SPAPD_LINE,
        T1.SPAPD_PART,
        T1.PT_DESC1,
        T4.RPLD_SRC_NBR,
        NVL(T1.SPAPD_QTY,0) SPAPD_QTY,
        T1.SPAP_DATE,
        NVL(T1.SO_NBR,‘‘) AS SO_NBR,
        NVL(T2.MOVD_MOV,‘‘) AS MOV_MOV1,
        NVL(TO_CHAR(T2.MOVD_LINE1),‘‘) AS MOVD_LINE1,
        NVL(TO_CHAR(T2.MOVD_QTY),‘‘) AS MOVD_QTY1,
        DECODE(T2.MOV_PST,0,‘未过账‘,1,‘已过账‘) AS MOV_PST1,
        NVL(T3.MOVD_MOV,‘‘) AS MOV_MOV2,
        NVL(TO_CHAR(T3.MOVD_LINE2),‘‘) AS MOVD_LINE2,
        NVL(TO_CHAR(T3.MOVD_QTY),‘‘) AS MOVD_QTY2,
        DECODE(T3.MOV_PST,0,‘未过账‘,1,‘已过账‘) AS MOV_PST2,
        NVL(T4.RPLD_NBR,‘‘) AS RPL_NBR1,
        NVL(TO_CHAR(T4.RPLD_LINE),‘‘) AS RPLD_LINE1,
        NVL(TO_CHAR(T4.RPLD_QTY),‘‘) AS RPLD_QTY1,
        DECODE(T4.RPL_PST,0,‘未过账‘,1,‘已过账‘) AS RPL_PST1,
        NVL(T5.DND_DN,‘‘) DN_DN,
        NVL(TO_CHAR(T5.DND_LINE),‘‘) DND_LINE,
        NVL(TO_CHAR(T5.DND_QTY_SHIP),‘‘) DND_QTY_SHIP,
        DECODE(T5.DN_PST,0,‘未过账‘,1,‘已过账‘) AS DN_PST,
        NVL(T6.RPLD_NBR,‘‘) AS RPL_NBR2,
        NVL(TO_CHAR(T6.RPLD_LINE),‘‘) AS RPLD_LINE2,
        NVL(TO_CHAR(T6.RPLD_QTY),‘‘) AS RPLD_QTY2,
        DECODE(T6.RPL_PST,0,‘未过账‘,1,‘已过账‘) AS RPL_PST2
 FROM T1
 JOIN T2 ON T2.MOVD_SRC_NBR=T1.SPAP_NBR AND T2.MOVD_SRC_LINE1=t1.SPAPD_LINE
 LEFT JOIN T3 ON T3.MOVD_SRC_NBR=T2.MOVD_MOV AND T3.MOVD_SRC_LINE2=T2.MOVD_LINE1
 LEFT JOIN T4 ON (T4.RPLD_SRC_NBR=T2.MOVD_MOV AND T4.RPLD_SRC_LINE=T2.MOVD_LINE1) OR (T4.RPLD_SRC_NBR = T3.MOVD_MOV AND T4.RPLD_SRC_LINE = T3.MOVD_LINE2)
 LEFT JOIN T5 ON T5.DND_DNA=T2.MOVD_MOV AND T5.DND_DNA_LINE=T2.MOVD_LINE1
 LEFT JOIN T6 ON T6.RPLD_SRC_NBR=T5.DND_DN AND T6.RPLD_SRC_LINE=T5.DND_LINE
 WHERE 1=1
 AND T1.SPAP_DATE >= :SPAP_DATE_FR
 AND T1.SPAP_DATE <= :SPAP_DATE_TO
 AND between2(T1.SPAP_CUST, :SPAP_CUST_FR, :SPAP_CUST_TO) = 1
 AND between2(T1.SPAP_NBR, :SPAP_NBR_FR, :SPAP_NBR_TO) = 1
 AND between2(T1.SPAPD_PART, :SPAPD_PART_FR, :SPAPD_PART_TO) = 1
 AND between2(T1.SPAP_NBR, :DN_DN_FR, :DN_DN_TO) = 1
 ORDER BY SPAP_NBR ASC

参考链接:http://www.360doc.com/content/14/0704/10/12414131_391906799.shtml

时间: 2024-10-14 08:46:35

with Table As QueryTable用法及实例的相关文章

【总结】alter table *** add constraint *** 用法

1. 主键约束 要对一个列加主键约束的话,这列就必须要满足的条件就是非空.因为主键约束:就是对一个列进行了约束,约束为(非空.不重复). [格式]alter table 表格名称 add constraint 约束名称 增加的约束类型 (列名) 例子:要对一个列加主键,列名为id,表名为emp alter table emp add constraint ppp primary key (id) 2. check约束就是给一列的数据进行了限制 [格式]alter table 表名称 add co

实现table表格各行变色代码实例

实现table表格各行变色代码实例:本章节介绍一下如何实现表格内容的隔行变色效果,这一效果的应用非常广泛,因为它有着较高的实用性,并且实现代码也比较简单,下面就通过代码实例介绍一下如何实现此效果.代码如下: <!DOCTYPE html> <html> <head> <meta charset=" utf-8"> <meta name="author" content="http://www.softw

jquery实现的拖动可以调整table单元格大小代码实例

jquery实现的拖动可以调整table单元格大小代码实例: 本章节介绍一下如果利用jquery实现表格单元格可以通过鼠标拖动调整大小的效果,当然如果让我们完全写代码的话,可能会比较的复杂,不过有现成的插件可以使用,只要简单的几个步骤就可以实现我们的要求. 一.引入相关库文件: 要使用相关插件,那就必须要引入相关的代码文件,如下: <script src="/js/jquery-1.8.0.min.js" type="text/javascript">&

Html.Listbox的用法(实例)

homecontroller控制器中的index动作代码如下: public actionresult index()        {            list<selectlistitem> list = new list<selectlistitem>()             {                 new selectlistitem(){text="张三",value="001"},              

alter table *** add constraint *** 用法

1.主键约束:要对一个列加主键约束的话,这列就必须要满足的条件就是分空因为主键约束:就是对一个列进行了约束,约束为(非空.不重复)以下是代码   要对一个列加主键,列名为id,表名为emp格式为:alter table 表格名称 add constraint 约束名称 增加的约束类型 (列名)例子:alter table emp add constraint ppp primary key (id)--------------------------------2.check约束:就是给一列的数

C# Timer用法及实例讲解

摘自:http://www.cnblogs.com/xcsn/archive/2013/05/10/3070485.html 1.C# Timer用法及实例详解 http://developer.51cto.com/art/200909/149829.htm http://www.cnblogs.com/OpenCoder/archive/2010/02/23/1672043.html 关于C# Timer类  在C#里关于定时器类就有3个 C# Timer使用的方法1.定义在System.Wi

table中的边框合并实例

<html><head><style type="text/css">table,th,td{border:1px solid blue;border-collapse:collapse;}</style></head> <body><table><tr><th>Firstname</th><th>Lastname</th></tr>

HTML常用标签用法及实例

HTML常用标签用法及实例1.<!--1.注释-->2.<!--2.DOCTPYE 声明文档类型-->3.<!--3.a--> <a href="http://www.baidu.com/">百度一下</a><br> <!--超链接标签-->4.<!--4.address <address> 标签定义文档或文章的作者/拥有者的联系信息.如果 <address> 元素位于 &

【Java学习笔记之二十二】解析接口在Java继承中的用法及实例分析

一.定义 Java接口(Interface),是一系列方法的声明,是一些方法特征的集合,一个接口只有方法的特征没有方法的实现,因此这些方法可以在不同的地方被不同的类实现,而这些实现可以具有不同的行为(功能). 接口定义的一般形式为: [访问控制符]interface <接口名> { 类型标识符final 符号常量名n = 常数: 返回值类型  方法名([参数列表]); … } 二.接口的特点 1.Java接口中的成员变量默认都是public,static,final类型的(都可省略),必须被显