运行下面的脚本时收到以下错误。任何帮助将不胜感激。
子查询返回的值超过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))
由于
答案 0 :(得分: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
相关联。