2016-04-18 30 views
0

で複数の値を返しました。サブクエリは、私は2つのテーブルを持っているアップデートセット句

stock_product個数をproductid個ごとに更新したいと思います。特定のオーダーIDに対して購入しています。ここで

は私のクエリです:

update product 
SET NoOfItems= (select sum(b.Quantity) 
from product as a,shippment_order_product as b 
where a.Product_ID=b.Product_ID 
group by a.Product_ID,b.Product_ID) 

これはエラーを与える:

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

これは、MSSQLです - あなたに複数の

update p 
SET p.NoOfItems = sum(s.Quantity) 
from product as p 
join shippment_order_product as s 
on p.Product_ID = s.Product_ID 
group by p.Product_ID 
にタグを付けます
関連する問題