1

运行以下脚本时,我收到以下错误。任何帮助,将不胜感激。

子查询返回超过 1 个值。当子查询跟随 =、!=、<、<=、>、>= 或子查询用作表达式时,这是不允许的。

脚本

DROP TABLE ProductBase_TEMP

GO

SELECT     *
INTO            ProductBase_TEMP
FROM         PILOT.dbo.PART

GO

UPDATE    ProductBase
SET              CurrentCost =
                          (SELECT     ProductBase_temp.UNIT_LABOR_COST + ProductBase_temp.UNIT_BURDEN_COST + ProductBase_temp.UNIT_SERVICE_COST AS VISUAL_Cost
                            FROM          ProductBase INNER JOIN
                                                   ProductBase_temp ON ProductBase.ProductNumber = ProductBase_TEMP.ID COLLATE Latin1_General_CI_AI)
WHERE     (ProductNumber COLLATE Latin1_General_CI_AI =
                          (SELECT     ProductBase_temp.ID
                            FROM      ProductBase_temp INNER JOIN
                                          ProductBase ON ProductBase_temp.ID COLLATE Latin1_General_CI_AI = ProductBase.ProductNumber))

谢谢

4

1 回答 1

1

问题是相关子查询中的连接:

UPDATE ProductBase
    SET CurrentCost = (SELECT ProductBase_temp.UNIT_LABOR_COST + ProductBase_temp.UNIT_BURDEN_COST + ProductBase_temp.UNIT_SERVICE_COST AS VISUAL_Cost
                       FROM ProductBase_temp
                       WHERE ProductBase.ProductNumber = ProductBase_TEMP.ID COLLATE Latin1_General_CI_AI
                      )
    WHERE (ProductNumber COLLATE Latin1_General_CI_AI =
              (SELECT ProductBase_temp.ID
               FROM ProductBase_temp 
               WHERE ProductBase_temp.ID COLLATE Latin1_General_CI_AI = ProductBase.ProductNumber
              )
          )

联接是ProductBase表的另一个副本,因此您会得到很多很多行(完整的结果集)。您希望将查询与外部相关联ProductBase

于 2013-05-28T16:06:18.477 回答