Home All Groups Group Topic Archive Search About
Author
21 Oct 2005 7:55 AM
savvaschr
Hello,
I have this Store Procedure and i am new in "Cursor" programming

The store Procedure is this

CREATE PROCEDURE Testing_Cursor AS
DECLARE @AccCode varchar(12)
DECLARE @YEAR varchar(4)
Declare CODE CURSOR
FOR
SELECT DISTINCT(NLAcc_Code)
FROM NLMovement_TMP
OPEN CODE
BEGIN
FETCH NEXT FROM  CODE INTO @AccCode
WHILE @@FETCH_STATUS = 0
  BEGIN
   DECLARE CYEAR CURSOR
    FOR SELECT DISTINCT(AccYear) FROM  NLMOVEMENT_TMP WHERE
NLACC_CODE=@ACCCODE
    OPEN CYEAR
    FETCH NEXT FROM CYEAR INTO @YEAR
    WHILE @@FETCH_STATUS = 0
      BEGIN
    SELECT SUM(MOVEMENT)
    FROM NLMOVEMENT_TMP
    WHERE NLACC_CODE=@ACCCODE
    AND ACCYEAR=@YEAR
      END
    CLOSE CYEAR
END
END
CLOSE CODE
GO
I have an endless lopp in the second WHILE @@FETCH_STATUS = 0
it avtually never goes into the begin - end code after .
Am i using the WHILE statment correct??
Can anyone find the what is wrong with it??

Thanks
Savvas

AddThis Social Bookmark Button