【发布时间】:2015-05-18 08:27:11
【问题描述】:
我正在开发一个表格,以便有一个用于采购目的的订单。
我的主窗体中有一个数据窗口作为报表对象。这个数据窗口(子报告)有一个选择来检索该订单表格的订单行。除了ORDER BY 子句外,一切正常。我需要按订单行号 (orderline.orderlineno) 对订单行进行降序排序。
我已经通过 Sybase Central > Interactive SQL 尝试了 SQL 语句,它以所需的顺序显示记录,但是在我的应用程序中使用该表单时,它显示按 orderline.forcompid 排序的记录。很奇怪
我的 SQL 语句中是否有任何错误或 Power Builder 中缺少的其他内容?
数据窗口(子报表)SQL
( SELECT orderline.orderlineno,
orderline.name,
orderline.unitid,
orderline.quantity,
orderline.makerref,
orderline.price,
orderline.discount ,
orderline.currencycode,
orderline.linecontent,
orderline.workorderid,
componenttype.compname,
componenttype.comptype,
componentunit.compno,
componentunit.serialno,
workorder.compjobid,
workorder.title,
workorder.woorigin
,orderline.notes
FROM orderline,
componenttype,
componentunit,
workorder
WHERE ( componentunit.comptypeid = componenttype.comptypeid ) and
( componentunit.compid = orderline.forcompid ) and
( orderline.workorderid = workorder.workorderid ) and
( orderline.orderid = :ll_OrderID ) AND
( orderline.status = 1 ) AND
( orderline.includeonform <> 0 )
union
SELECT orderline.orderlineno,
orderline.name,
orderline.unitid,
orderline.quantity,
orderline.makerref,
orderline.price,
orderline.discount ,
orderline.currencycode,
orderline.linecontent,
orderline.workorderid,
componenttype.compname,
componenttype.comptype,
componentunit.compno,
componentunit.serialno,
0,
NULL,
0
,orderline.notes
FROM orderline,
componenttype,
componentunit
WHERE orderline.workorderid IS NULL AND
( componentunit.comptypeid = componenttype.comptypeid ) and
( componentunit.compid = orderline.forcompid ) and
( orderline.orderid = :ll_OrderID ) AND
( orderline.status = 1 ) AND
( orderline.includeonform <> 0 )
union
SELECT orderline.orderlineno,
orderline.name,
orderline.unitid,
orderline.quantity,
orderline.makerref,
orderline.price,
orderline.discount ,
orderline.currencycode,
orderline.linecontent,
orderline.workorderid,
NULL,
NULL,
NULL,
NULL,
workorder.compjobid,
workorder.title,
workorder.woorigin
,orderline.notes
FROM orderline,
workorder
WHERE orderline.forcompid IS NULL AND
( orderline.workorderid = workorder.workorderid ) and
( orderline.orderid = :ll_OrderID ) AND
( orderline.status = 1 ) AND
( orderline.includeonform <> 0 )
union
SELECT orderline.orderlineno,
orderline.name,
orderline.unitid,
orderline.quantity,
orderline.makerref,
orderline.price,
orderline.discount ,
orderline.currencycode,
orderline.linecontent,
orderline.workorderid,
NULL,
NULL,
NULL,
NULL,
0,
NULL,
0
,orderline.notes
FROM orderline
WHERE orderline.forcompid IS NULL AND
( orderline.workorderid IS NULL ) and
( orderline.orderid = :ll_OrderID ) AND
( orderline.status = 1 ) AND
( orderline.includeonform <> 0 )
)
ORDER BY 1 ASC
** 编辑:修改后的 SQL **
SELECT orderline.orderlineno,
orderline.name,
orderline.unitid,
orderline.quantity,
orderline.makerref,
orderline.price,
orderline.discount,
orderline.currencycode,
orderline.linecontent,
orderline.workorderid,
componenttype.compname,
componenttype.comptype,
componentunit.compno,
componentunit.serialno,
workorder.compjobid,
workorder.title,
workorder.woorigin,
orderline.notes
FROM
( SELECT
A.orderlineno AS LineNo,
A.name as LineName ,
A.unitid AS Unit,
A.quantity As Qty,
A.makerref AS Maker,
A.price AS Price,
A.discount As Dsc,
A.currencycode As Curr,
A.linecontent As content,
A.workorderid AS WOID,
B.compname AS CName,
B.comptype As CType,
C.compno AS CNo,
C.serialno As Serial,
D.compjobid AS CJob,
D.title As Tit,
D.woorigin AS WOor,
A.notes As Nots
FROM orderline A,
componenttype B,
componentunit C,
workorder D
WHERE ( C.comptypeid = B.comptypeid ) and
( C.compid = A.forcompid ) and
( A.workorderid = D.workorderid ) and
( A.orderid = 40003774 ) AND
( A.status = 1 ) AND
( A.includeonform <> 0 )
union
SELECT
A1.orderlineno AS LineNo,
A1.name as LineName ,
A1.unitid AS Unit,
A1.quantity As Qty,
A1.makerref AS Maker,
A1.price AS Price,
A1.discount As Dsc,
A1.currencycode As Curr,
A1.linecontent As content,
A1.workorderid AS WOID,
B1.compname AS CName,
B1.comptype As CType,
C1.compno AS CNo,
C1.serialno As Serial,
0,
NULL,
0,
A1.notes As Nots
FROM orderline A1,
componenttype B1,
componentunit C1
WHERE A1.workorderid IS NULL AND
( C1.comptypeid = B1.comptypeid ) and
( C1.compid = A1.forcompid ) and
( A1.orderid = 40003774 ) AND
( A1.status = 1 ) AND
( A1.includeonform <> 0 )
union
SELECT
A2.orderlineno AS LineNo,
A2.name as LineName ,
A2.unitid AS Unit,
A2.quantity As Qty,
A2.makerref AS Maker,
A2.price AS Price,
A2.discount As Dsc,
A2.currencycode As Curr,
A2.linecontent As content,
A2.workorderid AS WOID,
NULL,
NULL,
NULL,
NULL,
B2.compjobid AS CJob,
B2.title As Tit,
B2.woorigin AS WOor,
A2.notes As Nots
FROM orderline A2,
workorder B2
WHERE A2.forcompid IS NULL AND
( A2.workorderid = B2.workorderid ) and
( A2.orderid = 40003774 ) AND
( A2.status = 1 ) AND
( A2.includeonform <> 0 )
union
SELECT
A3.orderlineno AS LineNo,
A3.name as LineName ,
A3.unitid AS Unit,
A3.quantity As Qty,
A3.makerref AS Maker,
A3.price AS Price,
A3.discount As Dsc,
A3.currencycode As Curr,
A3.linecontent As content,
A3.workorderid AS WOID,
NULL,
NULL,
NULL,
NULL,
0,
NULL,
0,
A3.notes As Nots
FROM orderline A3
WHERE A3.forcompid IS NULL AND
( A3.workorderid IS NULL ) and
( A3.orderid = 40003774 ) AND
( A3.status = 1 ) AND
( A3.includeonform <> 0 )
)
orderline,
componenttype,
componentunit,
workorder
ORDER BY 1 ASC
【问题讨论】:
-
外部选择的样子
-
@Sachu 我已经添加了主窗体的Sql语句。
-
我在询问
select ...(select... union select...)orderby 1 asc -
没有外部选择。我只是在应用 ORDER BY 子句之前添加了括号来封装 SQL。去掉括号结果和之前一样
-
像
select orderline.orderlineno,....from(select...union select...union)orderby 1 asc这样做一些事情,给内部选择中的每一列提供别名并在外部选择中使用它。这样我在我的pgms中实现排序。不知道它是否会解决你的问题
标签: sql sql-order-by sybase powerbuilder datawindow