Examine the following piece of code:
set @RM = 'some value'
set @BASEQTY = 1
DECLARE UOMSCHED CURSOR SCROLL FOR
SELECT UOFM,EQUOMQTY FROM tablename WHERE column = @RM
FETCH first FROM UOMSCHED INTO @UOFM,@EQUOMQTY
WHILE @@FETCH_STATUS = 0
set @cursor_Rows = @@Cursor_rows
SET @RMQTYCONVERTED = @BASEQTY /@EQUOMQTY
INSERT INTO RM_QTYS (RM_ID,[rmUOM],[QTYrequired])
FETCH next FROM UOMSCHED INTO @UOFM,@EQUOMQTY
In this example the SQL Query returns 5 rows. The @@cursor_rows variable also shows that the cursor has 5 rows.
However the variables @UOFM and @RMQTYCONVERTED always store the values of the first record. In other words the cursor does not seem to move to the next record. The purpose of this loop is to determine the quantity of something in 5 different units of measure. The units of measure and the conversion factors are stored in 'tablename'. All 5 calculated results are then inserted into another table 'RM_QTYS'. If there is a way to perform this without a cursor I am happy as well.