Click here to Skip to main content
15,903,388 members

Comments by Member 11377180 (Top 19 by date)

Member 11377180 15-Sep-15 7:07am View    
I feel something is wrong with cursor but not getting how to correct it
Member 11377180 15-Sep-15 7:06am View    
Hi..This is what i mentioned.When i run the statements you mentioned it will give me 14 rows(my desired output) but when i run entire thing it repeats result set. For example,
my result set is 3 rows. So the output wud be like:
Fruits:
Apple
Mango
Papaya

Fruits:
Apple
Mango
Papaya
Member 11377180 12-Sep-15 8:18am View    
Yes you are correct. I didnt put Fetch at the end since I thought it will go to first Fetch statement(one before while) after executing while loop. All working fine now,Thanks alot for the help!!
Member 11377180 12-Sep-15 5:07am View    
thanks..its working. but output is: Only first row is taken into cursor and its executing continously... is there anything im missing out? pls check my update proc below:



USE [Opening1]
GO
/****** Object: StoredProcedure [dbo].[HSR] ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
Alter PROC [dbo].[HSR]
AS
BEGIN
Declare @Showroomcode varchar(50),
@Startdate date,
@Stockno int,
@Servicetag varchar(50),
@TransType int,
@Qty int

BEGIN
DECLARE HSRCursor Cursor
STATIC FOR

select distinct a.Showroomcode,a.Stockno,b.Startdate,a.Servicetag, a.Qty ,a.TransType
from ConsIMEItrndata a,
(select Showroomcode,startdate,stockno,OpeningQty from IMTable) b
where a.Showroomcode=b.Showroomcode
and a.Stockno=b.Stockno

OPEN HSRCursor
IF @@CURSOR_ROWS > 0
BEGIN
FETCH NEXT FROM HSRCursor INTO @Showroomcode,@Stockno,@Startdate,@Servicetag,@Qty,@TransType
WHILE @@FETCH_STATUS = 0
begin

If ( @TransType=1100 or @Transtype=1300)
set @Qty=@Qty*1
else
set @Qty=@Qty* -1


Insert into HSR_OP_Bal(Showroomcode,Startdate,Stockno,Servicetag,OP) values(@Showroomcode,@Startdate,@Stockno,@Servicetag,@Qty)



end
end

CLOSE HSRCursor
DEALLOCATE HSRCursor
end
end
Member 11377180 12-Sep-15 2:49am View    
BEGIN



If ( @TransType=1100 or @Transtype=1300)
Declare @OP int
Begin
set @OP=Qty*1
end


else
Begin
set @OP=Qty* -1
end
Insert into HSR_OP_Bal(Showroomcode,Stockno,Startdate,Servicetag,OP) values(@Showroomcode,@Stockno,@Startdate,@Servicetag,@OP)


end



Im getting this error:Incorrect syntax near the keyword 'else'.