SQL Server 2000提交无法正常工作

时间:2013-09-17 16:35:39

标签: sql sql-server-2000

我试图使用此查询提交不起作用。总是得到相同的注册。

我在NOTA_CREDITO中有3个注册3,500并且总是获得“REGISTROS”中的第一个注册,即使我减少了金额和提交。

为什么提交

declare @idRegistroDescontar numeric(9)
declare @nroFacturaDesc varchar(12)
declare @montoDescontar decimal(24,0)
DECLARE @ITERACION INT;

DECLARE db_cursor CURSOR FOR  
SELECT id, DOCUMENTO, MONTO
FROM NOTA_CREDITO
order by DOCUMENTO, MONTO desc;

SET @ITERACION=0;
OPEN db_cursor   
FETCH NEXT FROM db_cursor INTO @ideliminar, @documento, @monto

WHILE @@FETCH_STATUS = 0   
BEGIN   
    SET @ITERACION = @ITERACION+1;

    select @idRegistroDescontar = isnull(a.ID,0), 
           @montoAdescontar = a.monto from registros a
    where a.documento = @documento 
    and   a.tipo_comprobante <> '7'
    and   (@monto*-1) <= a.monto;

    SET @idRegistroDescontar = ISNULL(CONVERT(VARCHAR,  @idRegistroDescontar), 0) ; 

    IF @idRegistroDescontar<>0 BEGIN
        begin transaction;
        update registros set monto = monto + @monto
        where id= @idRegistroDescontar;
        delete nota_credito where id= @ideliminar;
        commit;
    END

       FETCH NEXT FROM db_cursor INTO @ideliminar, @documento, @monto  
END   

CLOSE db_cursor   
DEALLOCATE db_cursor

0 个答案:

没有答案