0

我试图弄清楚为什么第 22 行和第 25 行的第二个 BEGIN/END 块错误。两种情况的 END。我错过了什么?另外我怎么能做一个查询而不是两个块?

    BEGIN

     SELECT

     l.partNum AS [Part Number]
    ,l.pricePerUOM AS [Price Per UOM]
    ,l.uom AS [UOM]
    ,SUM(CONVERT(DECIMAL(18,12), l.totalCostPerWS/l.pricePerUOM)) AS [Quantity/WS] INTO #temp
   FROM tbl_step s
    JOIN tbl_line l ON s.stepId = l.stepId
    WHERE s.revisionId = @revisionId
            AND ISNUMERIC(l.totalCostPerWS) > 0
            AND ISNUMERIC(l.pricePerUOM) > 0
        GROUP BY l.partNum, l.pricePerUOM, l.uom
    END

    BEGIN
        SELECT
             l.partNum AS [Part Number]
            ,l.pricePerUOM AS [Price Per UOM]
            ,l.uom AS [UOM]
        ,CASE
            WHEN l.partNum >=2 AND l.uom = 'liter' THEN (SELECT CONVERT(DECIMAL(18,12),[Quantity/WS] * 1000)
        END AS [Converted]
        ,CASE
            WHEN l.uom = 'milliliter' THEN (SELECT CONVERT(DECIMAL(18,12),[Quantity/WS] + l.pricePerUOM)
        END AS [Qnty/WS + Price per UOM]
        FROM #temp
            JOIN tbl_line l ON s.stepId = l.stepId
            JOIN tbl_step s ON l.stepId = s.stepId
            WHERE
                ISNUMERIC(l.totalCostPerWS) > 0
            AND ISNUMERIC(l.pricePerUOM) > 0
        GROUP BY l.partNum, l.pricePerUOM, l.uom
    END

谢谢你的帮助。F

4

2 回答 2

1

你也有这个:

FROM #temp
JOIN tbl_line l ON s.stepId = l.stepId
JOIN tbl_step s ON l.stepId = s.stepId

我想也许你的意思是:

FROM #temp AS t
JOIN tbl_line l ON t.stepId = l.stepId
JOIN tbl_step s ON l.stepId = s.stepId

但是,这将要求 #temp 有一个 stepId 列。我认为您需要退后一步,从更简化的查询开始,因为您现在所做的一大堆事情没有意义。

于 2012-05-15T22:12:22.627 回答
0

失去嵌入SELECT的:

,CASE
WHEN l.partNum >=2 AND l.uom = 'liter' THEN CONVERT(DECIMAL(18,12),[Quantity/WS] * 1000)
END AS [Converted]
,CASE
WHEN l.uom = 'milliliter' THEN CONVERT(DECIMAL(18,12),[Quantity/WS] + l.pricePerUOM)
END AS [Qnty/WS + Price per UOM]
于 2012-05-15T21:58:37.150 回答