cursor para datos siguientes
Publicado por Luis (3 intervenciones) el 02/06/2008 09:53:24
Buenas,
tengo un proc. almacenado donde quiero utilizar un cursor. El tema es que necesito actualizar(sustituir) los campos de cada columna actual por los de la columna posterior (o por los de la anterior, da igual)... y tengo el siguiente codigo pero no lo hace bien:
declare CURSOR1 cursor for
SELECT IDCPERSO, NOMPERSO, NOMAPELL1, NOMAPELL2, CODNIF FROM Tbl_En_Personas_Copia
open CURSOR1
fetch next from CURSOR1
into @IDCPERSO, @NOMPERSO, @NOMAPELL1, @NOMAPELL2, @CODNIF
while @@fetch_status = 0
begin
IF @EsPrimero=1
begin
UPDATE Copia set NOMPERSO=@NOMPERSO,
NOMAPELL1=@NOMAPELL2, NOMAPELL2=@NOMAPELL1, IF=@CODNIF
where IDCPERSO=@IDCPERSO
Set @EsPrimero=0
end
IF @EsPrimero=0
begin
UPDATE Copia set NOMPERSO=@NOMPERSO2,
NOMAPELL1=@NOMAPELL12, NOMAPELL2=@NOMAPELL22, CODNIF=@CODNIF2
where IDCPERSO=@IDCPERSO
end
-- Avanzamos otro registro
fetch next from CURSOR1
into @IDCPERSO2, @NOMPERSO2, @NOMAPELL12, @NOMAPELL22, @CODNIF2
end
-- cerramos el cursor
close CURSOR1
deallocate CURSOR1
Muchas gracias
tengo un proc. almacenado donde quiero utilizar un cursor. El tema es que necesito actualizar(sustituir) los campos de cada columna actual por los de la columna posterior (o por los de la anterior, da igual)... y tengo el siguiente codigo pero no lo hace bien:
declare CURSOR1 cursor for
SELECT IDCPERSO, NOMPERSO, NOMAPELL1, NOMAPELL2, CODNIF FROM Tbl_En_Personas_Copia
open CURSOR1
fetch next from CURSOR1
into @IDCPERSO, @NOMPERSO, @NOMAPELL1, @NOMAPELL2, @CODNIF
while @@fetch_status = 0
begin
IF @EsPrimero=1
begin
UPDATE Copia set NOMPERSO=@NOMPERSO,
NOMAPELL1=@NOMAPELL2, NOMAPELL2=@NOMAPELL1, IF=@CODNIF
where IDCPERSO=@IDCPERSO
Set @EsPrimero=0
end
IF @EsPrimero=0
begin
UPDATE Copia set NOMPERSO=@NOMPERSO2,
NOMAPELL1=@NOMAPELL12, NOMAPELL2=@NOMAPELL22, CODNIF=@CODNIF2
where IDCPERSO=@IDCPERSO
end
-- Avanzamos otro registro
fetch next from CURSOR1
into @IDCPERSO2, @NOMPERSO2, @NOMAPELL12, @NOMAPELL22, @CODNIF2
end
-- cerramos el cursor
close CURSOR1
deallocate CURSOR1
Muchas gracias
Valora esta pregunta


0