本文介绍了怎么做这个更新声明的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
update Products_TBL set Product_Price=(
SELECT sum(rn.Amount) / sum(rn.Quantity) AS Result
FROM Receipt_NoteDetalisTBL as rn
GROUP BY Product_Id
having rn.Product_Id between 1 and 1500
)
where Product_Id between 1 and 1500
this sql erorr ;
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.
推荐答案
DECLARE @a INT
SET @a = 1
WHILE @a < 1501
BEGIN
exec sp_executesql N'update Products_TBL set Product_Price=(
SELECT sum(rn.Amount) / sum(rn.Quantity) AS Result
FROM Receipt_NoteDetalisTBL as rn
GROUP BY Product_Id
having rn.Product_Id=@a) where Product_Id=@a'
SET @a = @a + 1
END
这篇关于怎么做这个更新声明的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!