子查询无法正常运行并返回表达式错误

时间:2016-09-19 07:06:42

标签: sql-server sql-server-2008

子查询

SELECT ISNULL(COUNT(A.PONo), 0)
    FROM (
        SELECT PM.PONo
            ,(
                SELECT SUM(TotalQty)
                FROM GRN_Details GD
                INNER JOIN GRN_Master GM ON GD.GRNNo = GM.GRNNo
                WHERE PONo = PM.PONo
                GROUP BY PONo
                ) [GRN_Qty]
            ,(
                SELECT SUM(qty)
                FROM PODetails PD
                WHERE RevisionNo = (
                        SELECT MAX(RevisionNo)
                        FROM PODetails
                        WHERE PONo = PD.PONo
                        )
                GROUP BY PD.PONo
                ) [PO_Qty]
        FROM POMaster PM
        WHERE RevisionNo = (
                SELECT Isnull(max(RevisionNo), 0)
                FROM POMaster
                WHERE PONo = PM.PONo
                )
            AND CONVERT(DATE, DocumentDate) = GETDATE()
            AND IsCancel = 0
            AND IsApproved = 1
        ) A
    WHERE A.GRN_Qty < A.PO_Qty 

0 个答案:

没有答案