![]() |
![]() |
| Paypal | FTP | CCD | Buscar | Trucos | Trabajo | Foros |
|
|||||||
| Registrarse | FAQ | Miembros | Calendario | Guía de estilo | Temas de Hoy |
|
|
Herramientas | Buscar en Tema | Desplegado |
|
#12
|
|||
|
|||
|
este es mi SP
CREATE PROCEDURE GEN_ANIMALES ( ESTABLECIMIENTO INTEGER, ACTUAL DATE, CON_EVENTO VARCHAR (1) CHARACTER SET NONE) RETURNS ( ANIMAL INTEGER, RP VARCHAR (10) CHARACTER SET NONE, SEXO INTEGER, RAZA INTEGER, RAZA_NOMBRE VARCHAR (50) CHARACTER SET NONE, RODEO INTEGER, CATEGORIA INTEGER, CATEGORIA_NOMBRE VARCHAR (50) CHARACTER SET NONE, CRONO_DENT INTEGER, ESTADO_REPRO INTEGER, NACIMIENTO DATE, EDAD INTEGER, POTRERO INTEGER, ACTIVO VARCHAR (1) CHARACTER SET NONE, COND_CORP INTEGER, GDR INTEGER, PESO INTEGER, RECHAZADO VARCHAR (1) CHARACTER SET NONE, FRAME FLOAT, ESTADO_ACTUAL VARCHAR (50) CHARACTER SET NONE, ULTIMO_EVENTO VARCHAR (255) CHARACTER SET NONE, EDADCAPTION VARCHAR (12) CHARACTER SET NONE, ESTADO_LACTACION INTEGER) AS -- estado_actual, ultimo_evento, datos_eve se deben calcular declare variable mensaje varchar(50); declare variable ultimo_eve integer; declare variable evento varchar(255); BEGIN for select ta.id_animal, ta.id_rp, cs.tipo, ta.raza, cr.nombre, ta.rodeo, ta.categoria, cc.nombre, ta.cronologia_dentaria, ta.estado_reproductivo, ta.fecha_nacimiento, ta.potrero, ta.activo, ta.condicion_corporal, ta.gdr, ta.peso, ta.rechazado, ta.frame, ta.estado_lactacion from tab_animales ta, cod_sexos cs, cod_categorias cc, cod_razas cr where (ta.establecimiento = :establecimiento) and (ta.sexo = cs.id_sexo) and (ta.raza = cr.id_raza) and (ta.categoria = cc.id_categoria) into :animal, :rp, :sexo, :raza, :raza_nombre, :rodeo, :categoria, :categoria_nombre, :crono_dent, :estado_repro, :nacimiento, otrero, :activo, :cond_corp, :GDR, eso, :rechazado, :frame, :ESTADO_LACTACIONdo begin if ( eso is null) thenbegin select first 1 ep.peso from eve_eventos ee, eve_peso ep where ee.id_evento = ep.id_evento and ee.animal = :animal and ee.establecimiento = :establecimiento order by ee.fecha desc into eso;end edad = (actual - nacimiento)/365; if (edad < 2) then EdadCaption = cast(((actual - nacimiento)/30) as varchar(6))||' meses'; else EdadCaption = cast(edad as varchar(6))||' años'; -- recupero el estado actual desde el sp genereado para calcular el estado actual select estado_actual from gen_estado_actual(:animal) into :estado_actual; --me fijo si tengo que generar_datos del evento if (con_evento = 'S') then begin select max(id_evento) from eve_eventos where (establecimiento = :establecimiento) and (animal = :animal) into :ultimo_eve; select nombretipoevento, infoevento from get_datos_eventos_grupal(:ultimo_eve, null, :establecimiento) into :evento, :ultimo_evento; ultimo_evento = evento || ', '||ultimo_evento; end SUSPEND; end END si yo comento esto if ( eso is null) thenbegin select first 1 ep.peso from eve_eventos ee, eve_peso ep where ee.id_evento = ep.id_evento and ee.animal = :animal and ee.establecimiento = :establecimiento order by ee.fecha desc into eso;end y esto select max(id_evento) from eve_eventos where (establecimiento = :establecimiento) and (animal = :animal) into :ultimo_eve; anda rápido pero si lo dejo se pone muy lento tengo todos los indices creados y utilizo firebird 1.5 |
|
|
Temas Similares
|
||||
| Tema | Autor | Foro | Respuestas | Último mensaje |
| Muy lento Sql | IVAND | SQL | 8 | 27-01-2010 03:59:52 |
| Prepare lento en Firebird.. y en MySQL?? | xander | MySQL | 11 | 01-11-2006 03:02:36 |
| ADO lento | CHiCoLiTa | Conexión con bases de datos | 6 | 28-07-2004 17:59:46 |
| MDI lento | tomasgarcia | OOP | 1 | 27-07-2004 20:28:05 |
| lento | carlomagno | Firebird e Interbase | 4 | 02-07-2004 13:48:08 |
|