日期:2014-05-18  浏览次数:20546 次

为什么MS不能同一列中引用别名,Case 语句能不能多条件组合,高手们都进来一下
SELECT   dbo.PiList.ProID,   dbo.Pro.ProNumber   AS   配件编号,   dbo.Pro.ChiName   AS   名称,  
            dbo.Pro.ChiDescription   AS   描述,   dbo.Pro.CustomProNumber   AS   客户产品编号,  
            dbo.PiList.QTY   AS   产品定单量,   Main.Num   AS   产品库存量,  
            CASE   WHEN   Main.Num   IS   NULL  
            THEN   Dbo.pilist.qty   ELSE   dbo.PiList.QTY   -   Main.Num   END   AS   产品实需求量,  
            dbo.PiList.QTY   *   dbo.CostList.Num   AS   配件定单量,   CASE   WHEN   Main.Num   IS   NULL  
            THEN   (CASE   WHEN   Costlist.num   IS   NULL  
            THEN   ' '   ELSE   pilist.qty   *   costlist.num   END)   ELSE   (CASE   WHEN   costlist.num   IS   NULL  
            THEN   ' '   ELSE   (dbo.PiList.QTY   -   Main.Num)   *   dbo.CostList.Num   END)  
            END   AS   配件余定单量,   Child.Num   AS   配件库存量,  
            CASE   WHEN   Main.Num   IS   NOT   NULL   AND   NOT   CostList.Num   IS   NULL   AND  
            Child.num   IS   NOT   NULL   THEN   (dbo.PiList.QTY   -   Main.Num)  
            *   dbo.CostList.Num   -   Child.Num   WHEN   Main.Num   IS   NOT   NULL   AND  
            CostList.Num   IS   NULL   THEN   ' '   WHEN   Main.Num   IS   NOT   NULL   AND  
            CostList.Num   IS   NOT   NULL   AND   Child.Num   IS   NULL  
            THEN   (dbo.PiList.QTY   -   Main.Num)   *   dbo.CostList.Num   WHEN   Main.Num   IS   NULL   AND  
            CostList.Num   IS   NOT   NULL   AND   CHILD.Num   IS   NOT   NULL  
            THEN   dbo.PiList.QTY   *   dbo.CostList.Num   -   Child.Num   WHEN   Main.Num   IS   NULL   AND  
            CostList.Num   IS   NULL   THEN   ' '   WHEN   Main.Num   IS   NULL   AND  
            CostList.Num   IS   NOT   NULL   AND   child.Num   IS   NULL  
            THEN   dbo.PiList.QTY   *   dbo.CostList.Num   END   AS   AS   配件实需求量
FROM   dbo.PiList   INNER   JOIN
            dbo.Cost   INNER   JOIN
                    (SELECT   dbo.CostList.CProID,   SUM(dbo.PiList.QTY) &nbs