使用案例条件和联接进行更新 [英] update with Case Conditions and Joins
本文介绍了使用案例条件和联接进行更新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
update K_RT_PurchaseDet PD inner join K_RT_Productdetails PS PD.product = PS.sno) set quantity =
(
案例
何时((数量) - @ TransferQnty)< = 0)
然后 attrited = ' true'
else
(quantity- @ TransferQnty)
结束
)
其中 PS.productname=@Purchaseid
我收到的错误如PD附近语法不正确...
解决方案
< blockquote>你不能在case语句中有赋值操作,它只能返回可以赋值的值在上面的代码中编辑数量。因此,将attrited ='true'替换为您要分配给数量的任何值。它将如下所示。
更新 PD 设置数量=
(
案例
何时((数量 - @ transferqnty )< = 0 )然后数量
其他(数量 - @ transeferqnty )
end
)
来自 K_RT_PurchaseDet as PD
inner join K_RT_Productdetails PS PD.product = PS.sno
其中 PS.productname = @ Purchas eid
在上面我的数量相同的值。
update K_RT_PurchaseDet PD inner join K_RT_Productdetails PS on PD.product=PS.sno ) set quantity=
(
case
when ((quantity-@TransferQnty)<=0)
then attrited='true'
else
(quantity-@TransferQnty)
end
)
where PS.productname=@Purchaseid
I am getting an error like "Incorrect syntax near PD"...
解决方案
You can't have assignment operation inside a case statement, it can only return value which can be assigned to quantity in your above code. So replace attrited = 'true' with whatever value you want to assign to quantity. It will be something like below.
update PD set quantity = ( case when ((quantity - @transferqnty) <= 0) then quantity else (quantity - @transeferqnty) end ) from K_RT_PurchaseDet as PD inner join K_RT_Productdetails as PS on PD.product = PS.sno where PS.productname = @Purchaseid
In the above i am maintaning the same value for quantity.
这篇关于使用案例条件和联接进行更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文