Click here to Skip to main content
15,881,204 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
SQL
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"...
Posted

1 solution

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.

SQL
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.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900