我正在编写以下查询来更新表格中的价格(PartsPricing):
Update PartsPricing
set ppPrice = CEILING((select PP.ppPrice from
#tmp_PartstoUpdate TPU join PartsPricing PP
on TPU.ppPartNumber = PP.ppPartNumber
where PP.ppConditionID = 9 and PP.ppDeleted = 0)*.5)
where ppID in (select ppID from #tmp_PartstoUpdate)
当我运行查询时,我收到以下错误:
Msg 512, Level 16, State 1, Line 1
Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, <, <= , >, >= or when the subquery is used as an expression.
The statement has been terminated.
我已经尝试过我可以在网上找到的所有可能的解决方案,但它们似乎都没有用。任何帮助将不胜感激。
答案 0 :(得分:1)
试试这个,基本上应该这样做:
Update PP
set ppPrice = CEILING(PP.ppPrice * 0.5)
FROM PartsPricing PP
INNER JOIN #tmp_PartstoUpdate TPU
ON TPU.ppPartNumber = PP.ppPartNumber
where PP.ppConditionID = 9 and PP.ppDeleted = 0
您的问题是,您的子查询返回多行,这会导致SQL Server中止。他不能将多行乘以一个值并将其分配给另一个值(除非您使用聚合)。