Tengo un Store Procedure en donde implemento un cursor,
pero este no me arroja los resultados que yo espero,
alguine me podria dar una mano y explicarme en donde estoy
fallando,
Agradeciendo de antemano toda la ayuda que me pudiesen
prestar, me despido
Luis Mizraim Gutierrez Pedroza
Analista de Sistemas
INFRA S.A.
lgutierrez@infrarad.com
www.infrarad.com
Caracas/Venezuela
CREATE PROCEDURE SP_IR_CurDistInv
AS
DECLARE @Item char(10), @Itemdesc1 char(15), @Itemdesc2
char(15), @Loc char(3), @Doctype char(1), @Docord char(8),
@User char(10), @quantity decimal(9), @Oldquantity
decimal(9), @Trxdt int, @Docdt int,
@Oldunitcost decimal(9), @unitcost decimal(9),
@newcost decimal(9), @Trxtm int, @Lev smallint,
@Entrada int, @Salida int
DECLARE Distribucion_Cursor CURSOR FOR
SELECT A.item_no, B.item_desc_1, B.item_desc_2, A.loc,
A.doc_type, A.doc_ord_no,
A.[user_name], A.quantity, A.old_quantity,
A.trx_dt, A.doc_dt, A.old_unit_cost,
A.unit_cost, A.new_unit_cost, A.trx_tm, A.lev_no
FROM IMINVTRX_SQL AS A
INNER JOIN IMITMIDX_SQL AS B ON A.item_no = B.item_no
WHERE A.item_no BETWEEN 'AAAAAAAAAA' AND 'ZZZZZZZZZZ'
AND A.doc_dt BETWEEN '20030901' AND '20030903'
AND A.loc BETWEEN '400' AND '400'
ORDER BY A.loc, A.item_no, A.trx_dt, A.trx_tm
OPEN Distribucion_Cursor
FETCH NEXT FROM Distribucion_Cursor
INTO @Item, @Itemdesc1, @Itemdesc2, @Loc, @Doctype,
@Docord,
@User, @quantity, @Oldquantity, @Trxdt, @Docdt,
@Oldunitcost, @unitcost, @newcost, @Trxtm, @Lev
WHILE @@FETCH_STATUS=0
BEGIN
IF @Lev<>1 and @Doctype='R'
BEGIN
SET @Entrada=@Quantity
SET @Salida=0
END
IF @Lev=0 AND @Doctype<>'P' AND @Doctype<>'A'
AND @Doctype<>'R' AND @Doctype<>'O' AND @Doctype<>'C'
BEGIN
SET @Salida=@Quantity
SET @Entrada=0
IF @Doctype='Q' and @Quantity<0
BEGIN
SET @Salida=@Quantity*-1
SET @Entrada=0
END
ELSE
BEGIN
SET @Entrada=@Quantity
SET @Salida=0
END
END
ELSE
IF @Doctype<>'P' AND @Doctype<>'A' AND
@Doctype<>'O' AND @Doctype<>'C'
BEGIN
SET @Entrada=@Quantity
SET @Salida=0
END
ELSE
IF @Lev=1 AND @Doctype='I'
BEGIN
SET @Salida=@Quantity
SET @Entrada=0
END
END
PRINT 'Item: ' + @Item
PRINT 'Descripcion: ' + @Itemdesc1 + ' ' + @Itemdesc2
PRINT 'Tipo Doc: ' + @Doctype
PRINT 'Numero Doc: ' + @Docord
PRINT 'Usuario: ' + @User
PRINT @Entrada
PRINT @Salida
PRINT @Trxdt
PRINT @Docdt
PRINT @unitcost
CLOSE Distribucion_Cursor
DEALLOCATE Distribucion_Cursor
Leer las respuestas