SQL - NO PUEDO HACER EL CURSOR, QUE PASA

 
Vista:

NO PUEDO HACER EL CURSOR, QUE PASA

Publicado por Gabylu (16 intervenciones) el 19/09/2002 23:50:42
ALGUIEN HECHEME LA MANO TENGO ESTE PROGRAMA PERO LO QUE ME INSERTA ES EN VEZ DE 5 REGISTROS QUE TIENE LA TABLA ADN. ME INSERTA 85,000 VECES EL PRIMER REGISTRO. EN QUE ESTOY MAL?????.

PORQUE EL CURSOR NO LEE SOLO LOS 5 VALORES QUE HAY EN LA TABLA?????.

SE ESTA HACIENDO COMO UN BUCLE INFINITO???
LES MENCIONO QUE ES LA PRIMERA VEZ QUE LO HAGO POR LO QUE NO SE QUE ES EXACTAMENTE UN CURSOR Y MENOS PARA QUE USAN LA SENTENCIA FETCH, ESTO LO HE ADECUADO GRACIAS A ISAIAS Y VICTOR.

CREATE PROCEDURE CONSULTA1 AS
DECLARE
@id int,
@desc varchar(255)

DECLARE cursorx CURSOR FOR
SELECT codigo_elektra,descripcion
from ADN
WHERE descripcion LIKE "S%"

OPEN cursorx

fetch cursorx into @id,@desc

WHILE (@@FETCH_STATUS <> -1)

begin

insert into local(codigo_elektra,descripcion)
values(@id,@desc)

end

close cursorx
Deallocate cursorx
GO



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:LO LOGRE¡¡¡¡¡¡¡

Publicado por Gabylu (16 intervenciones) el 20/09/2002 00:25:54
PORFIN LO LOGRE EL PROBLEMA ERA PRIMERO QUE DEBO PONERLE AL FETCH EL NEXT Y SEGUNDO DECLARAR NUEVAMENTE EL FETCH AL FINAL DE LA INSTRUCCION.

AUNQUE SIGO SIN ENTENDER MUY BIEN QUE HACE EL FETCH.

AQUI EL CODIGO FINAL.

if exists (select * from sysobjects where id = object_id(\'guest.CONSULTA1\') and sysstat & 0xf = 4)
drop procedure guest.CONSULTA1
GO

CREATE PROCEDURE CONSULTA1 AS
DECLARE
@id int,
@desc varchar(255)

DECLARE cursorx CURSOR FOR
SELECT codigo_elektra,descripcion
from ADN
WHERE descripcion LIKE \"S%\"

OPEN cursorx

fetch next from cursorx into @id,@desc
select @id,@desc

WHILE (@@FETCH_STATUS =0)

begin
insert into local(codigo,descripcion)
values(@id,@desc)

fetch next from cursorx into @id,@desc

end

close cursorx
Deallocate cursorx
GO


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

RE:LO LOGRE¡¡¡¡¡¡¡

Publicado por Islas, Isaías (5072 intervenciones) el 20/09/2002 00:42:38
Felicidades amiga !!!!, el esfuerzo al final, entrega sus frutos.

¿Que hace el FETCH?

Es como un READ NEXT, lee ( o se coloca ) en el siguiente apuntador de tu Cursor.

Saludos
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

RE:LO LOGRE¡¡¡¡¡¡¡

Publicado por Victor (11 intervenciones) el 20/09/2002 14:20:45
Ahora recién estoy entrando de nuevo al Foro, y muchas felicidades Gabylu, admiro mucho tu esfuerzo.
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

RE:LO LOGRE¡¡¡¡¡¡¡

Publicado por EDELRIO (540 intervenciones) el 20/09/2002 17:09:33
Enhorabuena Felicidades!!!!

Solo le pido revise lo que le puse en la intervencion anterior, respecto al cursor, es de tomarse en cuenta....

El Fetch sirve para pasar a leer el proximo registro...
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