i'am facing a problem to update stored procedure :
both are working right insert and update procedure but facing a problem when first time insert product but when update my quantity then it update but i want when any item add in cart then it no add that product :
@SessionId varchar(500),
@Product_Fkid int,
@size_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,size_Fkid) values (@SessionId,@Product_Fkid,@Qty,@size_Fkid)
Set @ReturnValue=1
end
set @count =(select COUNT(1) from dbo.MyCart where Product_Fkid=@Product_Fkid and SessionId=@SessionId and Qty!=0 )
if(@count =1)
begin
set @ReturnValue =3
end
else
begin
update dbo.MyCart
Set Qty=@Qty
where SessionId=@SessionId and Product_Fkid=@Product_Fkid
Set @ReturnValue=2
end
return @ReturnValue

Vipul MalhotraRank #276 · 9.1K reputationPosted Apr 11, 2016, 3:27 AM EDT
Devendra KumarRank #3,132 · 457 reputationPosted Apr 11, 2016, 3:44 AM EDT
Krishna Rajput SinghRank #605 · 4K reputationPosted Apr 11, 2016, 4:09 AM EDT
Khan Abrar AhmedRank #778 · 3K reputationPosted Apr 11, 2016, 4:10 AM EDT
BEGIN
Set @count=(Select COUNT(1) from dbo.MyCart where SessionId=@SessionId and Product_Fkid=@Product_Fkid AND ISNULL(Qty,0)=0 )
if(@count=0)
begin
Insert into dbo.MyCart(SessionId,Product_Fkid,Qty,size_Fkid) values (@SessionId,@Product_Fkid,@Qty,@size_Fkid)
Set @ReturnValue=1
return @ReturnValue
END
set @count =(select COUNT(1) from dbo.MyCart where Product_Fkid=@Product_Fkid and SessionId=@SessionId and ISNULL(Qty,0)!=0 )
if(@count =1)
begin
set @ReturnValue =3
end
else
begin
update dbo.MyCart
Set Qty=@Qty
where SessionId=@SessionId and Product_Fkid=@Product_Fkid
Set @ReturnValue=2
end
return @ReturnValue
Devendra KumarRank #3,132 · 457 reputationPosted Apr 11, 2016, 4:51 AM EDT
Khan Abrar AhmedRank #778 · 3K reputationPosted Apr 11, 2016, 4:57 AM EDT
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questionsTop experts