Docentes em disciplinas compartilhadas
De MSTECH wiki
1 /*
2 - Docentes em disciplinas compartilhadas (exibir ano letivo, curso, turma, disciplina)
3 */
4
5 USE SGP_GestaoPedagogica
6 GO
7
8 SELECT
9 Uad.uad_nome AS DRE
10 , Esc.esc_nome AS Escola
11 , Pes.pes_nome as Docente
12 , Coc.coc_matricula AS [login]
13 , Tdc.tdc_nome AS TipoDocente
14 , Cal.cal_ano AS AnoLetivo
15 , Tur.tur_codigo AS Turma
16 , Tud.tud_nome AS Disciplina
17 , Tur.tur_id
18 , Tud.tud_id
19 , tud_tipo
20 , Tur.esc_id
21 , (SELECT COUNT(alu_id) FROM MTR_MatriculaTurma WITH(NOLOCK) WHERE tur_id = Tur.tur_id AND mtu_situacao <> 3) AS QtAlunos
22 FROM TUR_TurmaDocente Tdt WITH(NOLOCK)
23 INNER JOIN TUR_TurmaDisciplina Tud WITH(NOLOCK)
24 ON Tud.tud_id = Tdt.tud_id
25 inner join TUR_TurmaRelTurmaDisciplina RelTud WITH(NOLOCK)
26 ON Reltud.tud_id = Tud.tud_id
27 INNER JOIN ACA_TipoDocente Tdc WITH(NOLOCK)
28 ON Tdc.tdc_posicao = Tdt.tdt_posicao
29 INNER JOIN TUR_Turma Tur WITH(NOLOCK)
30 ON Tur.tur_id = RelTud.tur_id
31 INNER JOIN ACA_CalendarioAnual Cal WITH(NOLOCK)
32 ON Cal.cal_id = Tur.cal_id
33 INNER JOIN ACA_Docente Doc WITH(NOLOCK)
34 ON Doc.doc_id = Tdt.doc_id
35 INNER JOIN RHU_Colaborador Col WITH(NOLOCK)
36 ON Col.col_id = Doc.col_id
37 AND Col.col_situacao <> 3
38 INNER JOIN RHU_ColaboradorCargo Coc WITH(NOLOCK)
39 ON Coc.col_id = Col.col_id
40 AND Coc.crg_id = Tdt.crg_id
41 AND Coc.coc_id = Tdt.coc_id
42 AND Coc.coc_situacao <> 3
43 INNER JOIN Synonym_PES_Pessoa Pes WITH(NOLOCK)
44 ON Pes.pes_id = Col.pes_id
45 INNER JOIN Synonym_SYS_Usuario Usu WITH(NOLOCK)
46 ON Usu.pes_id = Pes.pes_id
47 AND Usu.usu_situacao <> 3
48 INNER JOIN ESC_Escola Esc WITH(NOLOCK)
49 ON Esc.esc_id = Tur.esc_id
50 INNER JOIN Synonym_SYS_UnidadeAdministrativa Uad WITH(NOLOCK)
51 ON Uad.ent_id = Esc.ent_id
52 AND Uad.uad_id = Esc.uad_idSuperiorGestao
53 WHERE
54 Tdt.tdt_situacao = 1
55 AND Tur.tur_situacao = 1
56 AND Tud.tud_situacao <> 3
57
58 -- Compartilhada
59 AND Tud.tud_tipo = 17
60
61 order by
62 Uad.uad_nome
63 , Esc.esc_nome
64 , Pes.pes_nome
65 , Coc.coc_matricula
66 , Tur.tur_codigo
67 , Tud.tud_nome
68 , Tdc.tdc_nome