ejecutar cursor dentro de un store procedure

19/01/2005 - 16:47 por store procedure y cursores | Informe spam
Hola tengo este cursor pero para tenerlo almacenado y ejecutarlo varias veces
desde asp tengo que ejecutar un store procedure que lo invoque como hago
??



USE BIPE
DECLARE tnames_cursor3 CURSOR

FOR
select COD_NIVEL from FL_Niveles_Generales where papa='123000' order by
cod_nivel

declare @actividad as nvarchar(50)
OPEN tnames_cursor3
FETCH NEXT FROM tnames_cursor3 INTO @actividad
WHILE @@FETCH_STATUS = 0
BEGIN

SELECT A.cod_actividad,
isnull((select b.nombre from FL_actividad as b where a.cod_actividad
=b.cod_actividad and Month (A.fecha)='1'),'')as jan,
isnull((select b.nombre from FL_actividad as b where a.cod_actividad
=b.cod_actividad and Month (A.fecha)='2'),'')as feb,
isnull((select b.nombre from FL_actividad as b where a.cod_actividad
=b.cod_actividad and Month (A.fecha)='3'),'')as mar,
isnull((select b.nombre from FL_actividad as b where a.cod_actividad
=b.cod_actividad and Month (A.fecha)='4'),'')as apr,
isnull((select b.nombre from FL_actividad as b where a.cod_actividad
=b.cod_actividad and Month (A.fecha)='5'),'')as marc,
isnull((select b.nombre from FL_actividad as b where a.cod_actividad
=b.cod_actividad and Month (A.fecha)='6'),'')as may,
isnull((select b.nombre from FL_actividad as b where a.cod_actividad
=b.cod_actividad and Month (A.fecha)='7'),'')as jun,
isnull((select b.nombre from FL_actividad as b where a.cod_actividad
=b.cod_actividad and Month (A.fecha)='8'),'')as jul,
isnull((select b.nombre from FL_actividad as b where a.cod_actividad
=b.cod_actividad and Month (A.fecha)='9'),'')as aug,
isnull((select b.nombre from FL_actividad as b where a.cod_actividad
=b.cod_actividad and Month (A.fecha)='10'),'')as sep,
isnull((select b.nombre from FL_actividad as b where a.cod_actividad
=b.cod_actividad and Month (A.fecha)='11'),'')as oct,
isnull((select b.nombre from FL_actividad as b where a.cod_actividad
=b.cod_actividad and Month (A.fecha)='12'),'')as nov
FROM FL_actividad AS A
WHERE A.cod_general='002_1_001_16082712_001' AND A.cod_actividad=@actividad


FETCH NEXT FROM tnames_cursor3 INTO @actividad
END
CLOSE tnames_cursor3
DEALLOCATE tnames_cursor3

Preguntas similare

Leer las respuestas

#1 Maxi
19/01/2005 - 16:52 | Informe spam
Hola, porque no nos cuentas que quieres hacer y no como lo haces ;), el uso
de cursores es una tecnica muy mala de verdad porque es totalmente
ineficiente. Si nos cuentas un poco mas quizas podamos darte una mano para
eliminar el cursor :-D


Salu2
Maxi


"store procedure y cursores" <store procedure y
escribió en el mensaje
news:
Mostrar la cita
#2 store procedure y cursores
19/01/2005 - 18:07 | Informe spam
Hola gracias bueno tengo

un query me devuelve

id actividad
001 internet
002 tv
003 radio

y tengo que ejecutarlo n veces para cada actividad y me devuelve esto

actividad mes descripcion
001 01 buenisima
001 02 mala
001 03 regular

estos resultados tengo que obtenerlos para n actividades y quiero
visualizarlas así

actividad ene feb mar abri may jun jul
agos ...dec
001 buenisima mala regular x
002 excelente menos mala xxxx xxx xxx xxx
xx xx

"Maxi" escribió:

Mostrar la cita
#3 ulises
19/01/2005 - 20:06 | Informe spam
Basta con hacer un join, no necesitas el cursor para nada :

SELECT A.cod_actividad,
MAX(CASE WHEN Month(A.fecha)= 1 THEN A.Nombre ELSE '' END)
as Ene,
MAX(CASE WHEN Month(A.fecha)= 2 THEN A.Nombre ELSE '' END)
as Feb,
...
FROM FL_Niveles_Generales N JOIN FL_actividad A
ON N.COD_NIVEL = A.cod_actividad
WHERE A.cod_general='002_1_001_16082712_001'
AND N.papa='123000'
GROUP BY A.cod_actividad
ORDER BY A.cod_atividad

Saludos,
Ulises

Mostrar la cita
devuelve esto
Mostrar la cita
quiero
Mostrar la cita
jun jul
Mostrar la cita
xxx
Mostrar la cita
lo haces ;), el uso
Mostrar la cita
totalmente
Mostrar la cita
darte una mano para
Mostrar la cita
ejecutarlo varias
Mostrar la cita
invoque como hago
Mostrar la cita
papa='123000' order by
Mostrar la cita
a.cod_actividad
Mostrar la cita
a.cod_actividad
Mostrar la cita
a.cod_actividad
Mostrar la cita
a.cod_actividad
Mostrar la cita
a.cod_actividad
Mostrar la cita
a.cod_actividad
Mostrar la cita
a.cod_actividad
Mostrar la cita
a.cod_actividad
Mostrar la cita
a.cod_actividad
Mostrar la cita
a.cod_actividad
Mostrar la cita
a.cod_actividad
Mostrar la cita
a.cod_actividad
Mostrar la cita
Ads by Google
Search Busqueda sugerida