[英]How to insert the result in the desired row? SQL Server
I need the result that I got to be inserted in the right row.我需要将结果插入正确的行。
DECLARE @DiscPrice float;
SET @DiscPrice = (SELECT Prod.priceProd - Prod.priceProd / 100 * Prod.disc
FROM Prod
WHERE id_prod = 1);
UPDATE Prod
SET priceDisc = @DiscPrice
WHERE id_prod = 1;
SELECT * FROM Prod;
That is, instead of WHERE id_prod = 1
, there was something that inserted the desired result in all rows.也就是说,不是
WHERE id_prod = 1
,而是在所有行中插入了所需的结果。
I'm not sure I made myself clear, but I hope that you will understand.我不确定我是否说清楚了,但我希望你能理解。
I think you want我想你想要
UPDATE Prod
SET priceDisc = ((priceProd - priceProd) / 100) * disc
WHERE id_prod = 1;
There is no need to use a variable or a query to assign the value to it.无需使用变量或查询来为其分配值。
You can directly update the query as below您可以直接更新查询如下
UPDATE Prod SET priceDisc =((priceProd - priceProd) / 100 * disc)
This will update the data in all rows这将更新所有行中的数据
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.