Devendra  Kumar

Devendra Kumar

  • NA
  • 517
  • 244.4k

how to update quantity in sqlserver.

Mar 18 2016 8:01 AM
how to update my quantity:
 
i get error when insert my quantity:
 
first time count 0 then insert but second time insert same product then get error how to get second time my quantity:like if first time insert then quantity one then we add same product then quantity 1+1 
create  PROCEDURE [dbo].[Sp_AddToMyCart]
@SessionId varchar(500),
@Product_Fkid int,
@Qty int
AS
Declare @count int,@ReturnValue int
BEGIN
Set @count=(Select COUNT(1) from dbo.MyCart where SessionId=@SessionId and Product_Fkid=@Product_Fkid)
if(@count=0)
begin
Insert into dbo.MyCart(SessionId,Product_Fkid,Qty) values (@SessionId,@Product_Fkid,@Qty)
Set @ReturnValue=1
end
else
begin
update dbo.MyCart
Set Qty=@Qty
where SessionId=@SessionId and Product_Fkid=@Product_Fkid
Set @ReturnValue=2
end
return @ReturnValue
END

Answers (1)