Fórum Como fazer as 2 Procedures em 1? #510852
16/02/2015
0
Amigos fiz duas procedures, mas preciso fazer uma só, não estou conseguindo fazer os cálculos da procedure que calculas as FALTAS funcionar dentro da procedure que calcula as NOTAS.
PROCEDURE DAS NOTAS
PROCEDURE DAS FALTAS
PROCEDURE DAS NOTAS
BEGIN
FOR
select n.codigo,
n.disciplina_notas,
n.matricula_aluno_notas,
n.codigo_turma_notas,
al.numero,
(select n1.observacao_nota_1 + n1.observacao_nota_2 + n1.observacao_nota_3 +
n1.trab_indiv_nota_1 + n1.trab_indiv_nota_2 + n1.trab_indiv_nota_3 +
n1.trab_grupo_nota_1 + n1.trab_grupo_nota_2 + n1.trab_grupo_nota_3 +
n1.prova_nota_1 + n1.prova_nota_2 + n1.prova_nota_3
from notas n1
where n1.disciplina_notas = n.disciplina_notas
and n1.matricula_aluno_notas = n.matricula_aluno_notas
and n1.codigo_turma_notas = n.codigo_turma_notas
and n1.bimestre = '1 SEMESTRE') nota_1SEM,
(select n2.observacao_nota_1 + n2.observacao_nota_2 + n2.observacao_nota_3 +
n2.trab_indiv_nota_1 + n2.trab_indiv_nota_2 + n2.trab_indiv_nota_3 +
n2.trab_grupo_nota_1 + n2.trab_grupo_nota_2 + n2.trab_grupo_nota_3 +
n2.prova_nota_1 + n2.prova_nota_2 + n2.prova_nota_3
from notas n2
where n2.disciplina_notas = n.disciplina_notas
and n2.matricula_aluno_notas = n.matricula_aluno_notas
and n2.codigo_turma_notas = n.codigo_turma_notas
and n2.bimestre = '2 SEMESTRE') nota_2SEM,
(select n3.recuperacao1
from notas n3
where n3.disciplina_notas = n.disciplina_notas
and n3.matricula_aluno_notas = n.matricula_aluno_notas
and n3.codigo_turma_notas = n.codigo_turma_notas
and n3.bimestre = '1 RECUPERACAO') nota_1REC,
(select n4.chamada2_regular
from notas n4
where n4.disciplina_notas = n.disciplina_notas
and n4.matricula_aluno_notas = n.matricula_aluno_notas
and n4.codigo_turma_notas = n.codigo_turma_notas
and n4.bimestre = '2 CHAMADA') CHAMADA2,
(select n5.recuperacao1
from notas n5
where n5.disciplina_notas = n.disciplina_notas
and n5.matricula_aluno_notas = n.matricula_aluno_notas
and n5.codigo_turma_notas = n.codigo_turma_notas
and n5.bimestre = '1 REC_PERIODO') REC_PER,
(select n6.chamada2_periodo
from notas n6
where n6.disciplina_notas = n.disciplina_notas
and n6.matricula_aluno_notas = n.matricula_aluno_notas
and n6.codigo_turma_notas = n.codigo_turma_notas
and n6.bimestre = '2CHAM_PERIODO') CHAM2_PER
from notas n left join alunoturma al on n.matricula_aluno_notas = al.matricula_aluno
and n.codigo_turma_notas = al.codigo_turma
where n.escola =:escola
and n.codigo_turma_notas =:turma
and n.disciplina_notas =:disciplina
and n.bimestre = '1 SEMESTRE'
group by n.codigo,
n.disciplina_notas,
n.matricula_aluno_notas,
n.codigo_turma_notas,
al.numero
order by numero
INTO :CODIGO,
:DISCIPLINA_NOTAS,
:MATRICULA_ALUNO_NOTAS,
:CODIGO_TURMA_NOTAS,
:NUMERO,
:NOTA_1SEM,
:NOTA_2SEM,
:NOTA_1REC,
:CHAMADA2,
:REC_PER,
:CHAM2_PER
DO
BEGIN
SUSPEND;
END
END
PROCEDURE DAS FALTAS
BEGIN
FOR
select f.codigo_disciplina, f.matricula_aluno, f.codigo_turma, al.numero,
count(case when f.bimestre = '1 SEMESTRE' and f.frequencia_falta_1 = 'F' then 1 end) +
count(case when f.bimestre = '1 SEMESTRE' and f.frequencia_falta_2 = 'F' then 1 end) +
count(case when f.bimestre = '1 SEMESTRE' and f.frequencia_falta_3 = 'F' then 1 end) +
count(case when f.bimestre = '1 SEMESTRE' and f.frequencia_falta_4 = 'F' then 1 end) +
count(case when f.bimestre = '1 SEMESTRE' and f.frequencia_falta_5 = 'F' then 1 end) +
count(case when f.bimestre = '1 SEMESTRE' and f.frequencia_falta_6 = 'F' then 1 end) +
count(case when f.bimestre = '1 SEMESTRE' and f.frequencia_falta_7 = 'F' then 1 end) +
count(case when f.bimestre = '1 SEMESTRE' and f.frequencia_falta_8 = 'F' then 1 end) +
count(case when f.bimestre = '1 SEMESTRE' and f.frequencia_falta_9 = 'F' then 1 end) +
count(case when f.bimestre = '1 SEMESTRE' and f.frequencia_falta_10 = 'F' then 1 end) +
count(case when f.bimestre = '1 SEMESTRE' and f.frequencia_falta_11 = 'F' then 1 end) +
count(case when f.bimestre = '1 SEMESTRE' and f.frequencia_falta_12 = 'F' then 1 end) +
count(case when f.bimestre = '1 SEMESTRE' and f.frequencia_falta_13 = 'F' then 1 end) +
count(case when f.bimestre = '1 SEMESTRE' and f.frequencia_falta_14 = 'F' then 1 end) +
count(case when f.bimestre = '1 SEMESTRE' and f.frequencia_falta_15 = 'F' then 1 end) +
count(case when f.bimestre = '1 SEMESTRE' and f.frequencia_falta_16 = 'F' then 1 end) +
count(case when f.bimestre = '1 SEMESTRE' and f.frequencia_falta_17 = 'F' then 1 end) +
count(case when f.bimestre = '1 SEMESTRE' and f.frequencia_falta_18 = 'F' then 1 end) +
count(case when f.bimestre = '1 SEMESTRE' and f.frequencia_falta_19 = 'F' then 1 end) +
count(case when f.bimestre = '1 SEMESTRE' and f.frequencia_falta_20 = 'F' then 1 end) +
count(case when f.bimestre = '1 SEMESTRE' and f.frequencia_falta_21 = 'F' then 1 end) +
count(case when f.bimestre = '1 SEMESTRE' and f.frequencia_falta_22 = 'F' then 1 end) +
count(case when f.bimestre = '1 SEMESTRE' and f.frequencia_falta_23 = 'F' then 1 end) +
count(case when f.bimestre = '1 SEMESTRE' and f.frequencia_falta_24 = 'F' then 1 end) +
count(case when f.bimestre = '1 SEMESTRE' and f.frequencia_falta_25 = 'F' then 1 end) +
count(case when f.bimestre = '1 SEMESTRE' and f.frequencia_falta_26 = 'F' then 1 end) +
count(case when f.bimestre = '1 SEMESTRE' and f.frequencia_falta_27 = 'F' then 1 end) +
count(case when f.bimestre = '1 SEMESTRE' and f.frequencia_falta_28 = 'F' then 1 end) +
count(case when f.bimestre = '1 SEMESTRE' and f.frequencia_falta_29 = 'F' then 1 end) +
count(case when f.bimestre = '1 SEMESTRE' and f.frequencia_falta_30 = 'F' then 1 end) +
count(case when f.bimestre = '1 SEMESTRE' and f.frequencia_falta_31 = 'F' then 1 end) as QtdFaltas_1Sem,
count(case when f.bimestre = '2 SEMESTRE' and f.frequencia_falta_1 = 'F' then 1 end) +
count(case when f.bimestre = '2 SEMESTRE' and f.frequencia_falta_2 = 'F' then 1 end) +
count(case when f.bimestre = '2 SEMESTRE' and f.frequencia_falta_3 = 'F' then 1 end) +
count(case when f.bimestre = '2 SEMESTRE' and f.frequencia_falta_4 = 'F' then 1 end) +
count(case when f.bimestre = '2 SEMESTRE' and f.frequencia_falta_5 = 'F' then 1 end) +
count(case when f.bimestre = '2 SEMESTRE' and f.frequencia_falta_6 = 'F' then 1 end) +
count(case when f.bimestre = '2 SEMESTRE' and f.frequencia_falta_7 = 'F' then 1 end) +
count(case when f.bimestre = '2 SEMESTRE' and f.frequencia_falta_8 = 'F' then 1 end) +
count(case when f.bimestre = '2 SEMESTRE' and f.frequencia_falta_9 = 'F' then 1 end) +
count(case when f.bimestre = '2 SEMESTRE' and f.frequencia_falta_10 = 'F' then 1 end) +
count(case when f.bimestre = '2 SEMESTRE' and f.frequencia_falta_11 = 'F' then 1 end) +
count(case when f.bimestre = '2 SEMESTRE' and f.frequencia_falta_12 = 'F' then 1 end) +
count(case when f.bimestre = '2 SEMESTRE' and f.frequencia_falta_13 = 'F' then 1 end) +
count(case when f.bimestre = '2 SEMESTRE' and f.frequencia_falta_14 = 'F' then 1 end) +
count(case when f.bimestre = '2 SEMESTRE' and f.frequencia_falta_15 = 'F' then 1 end) +
count(case when f.bimestre = '2 SEMESTRE' and f.frequencia_falta_16 = 'F' then 1 end) +
count(case when f.bimestre = '2 SEMESTRE' and f.frequencia_falta_17 = 'F' then 1 end) +
count(case when f.bimestre = '2 SEMESTRE' and f.frequencia_falta_18 = 'F' then 1 end) +
count(case when f.bimestre = '2 SEMESTRE' and f.frequencia_falta_19 = 'F' then 1 end) +
count(case when f.bimestre = '2 SEMESTRE' and f.frequencia_falta_20 = 'F' then 1 end) +
count(case when f.bimestre = '2 SEMESTRE' and f.frequencia_falta_21 = 'F' then 1 end) +
count(case when f.bimestre = '2 SEMESTRE' and f.frequencia_falta_22 = 'F' then 1 end) +
count(case when f.bimestre = '2 SEMESTRE' and f.frequencia_falta_23 = 'F' then 1 end) +
count(case when f.bimestre = '2 SEMESTRE' and f.frequencia_falta_24 = 'F' then 1 end) +
count(case when f.bimestre = '2 SEMESTRE' and f.frequencia_falta_25 = 'F' then 1 end) +
count(case when f.bimestre = '2 SEMESTRE' and f.frequencia_falta_26 = 'F' then 1 end) +
count(case when f.bimestre = '2 SEMESTRE' and f.frequencia_falta_27 = 'F' then 1 end) +
count(case when f.bimestre = '2 SEMESTRE' and f.frequencia_falta_28 = 'F' then 1 end) +
count(case when f.bimestre = '2 SEMESTRE' and f.frequencia_falta_29 = 'F' then 1 end) +
count(case when f.bimestre = '2 SEMESTRE' and f.frequencia_falta_30 = 'F' then 1 end) +
count(case when f.bimestre = '2 SEMESTRE' and f.frequencia_falta_31 = 'F' then 1 end) as QtdFaltas_2Sem
from FREQUENCIA f left join ALUNOTURMA al on (f.codigo_turma = al.codigo_turma ) and
(f.matricula_aluno = al.matricula_aluno)
where f.escola =:escola
and f.codigo_turma =:turma
and f.codigo_disciplina =:disciplina
group by f.codigo_disciplina, f.matricula_aluno, f.codigo_turma, al.numero
order by al.numero
INTO :CODIGO_DISCIPLINA,
:MATRICULA_ALUNO,
:CODIGO_TURMA,
:NUMERO,
:QTDFALTAS_1SEM,
:QTDFALTAS_2SEM
DO
BEGIN
SUSPEND;
END
END
Osmar
Curtir tópico
+ 0
Responder
Clique aqui para fazer login e interagir na Comunidade :)