SQL - cursor para datos siguientes

 
Vista:

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
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder

RE:cursor para datos siguientes

Publicado por Jim Miñano (1 intervención) el 11/06/2008 20:38:33
creo q el problema esta en

fetch next from CURSOR1
into @IDCPERSO2, @NOMPERSO2, @NOMAPELL12, @NOMAPELL22, @CODNIF2

@IDCPERSO2 pero tus updates estan comparando con @IDCPERSO

eso es a priimera vista una observacion,

saludos

www.solucionesperu.com
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar