-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathSQL025.sql
52 lines (48 loc) · 1.91 KB
/
SQL025.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
/*
* PLT047 - Script para listagem dos totais de alunos em situação de pre-matricula / outros
* @param CODFILIAL Código da Filial
* @param CODPERLET Código do Periodo Letivo
*
* @author Marcelo Valvassori Bittencourt
* @mail webmaster@pallottism.com.br
* @version 1.0 bitts 05/01/2017
*/
DECLARE
@CODPERLET VARCHAR(10) = '2017',
@CODFILIAL VARCHAR(1) = '3';
SELECT
A.CODTURMA, ISNULL( [PRE MATRICULADOS].TOTAL, 0) AS TOTAL_PREMTR, ISNULL( [OUTROS].TOTAL, 0) AS TOTAL_OUTROS
FROM
SMATRICPL AS A
LEFT JOIN SPLETIVO B (NOLOCK) ON
B.IDPERLET = A.IDPERLET AND
B.CODCOLIGADA = A.CODCOLIGADA AND
B.CODFILIAL = A.CODFILIAL
LEFT JOIN (
SELECT
CODCOLIGADA, CODFILIAL, CODTURMA, IDHABILITACAOFILIAL, IDPERLET, COUNT(RA) AS TOTAL
FROM SMATRICPL
WHERE CODSTATUS IN (45)
GROUP BY CODCOLIGADA, CODFILIAL, CODTURMA, IDHABILITACAOFILIAL, IDPERLET
) [PRE MATRICULADOS] (CODCOLIGADA, CODFILIAL, CODTURMA, IDHABILITACAOFILIAL, IDPERLET, TOTAL) ON
A.CODCOLIGADA = [PRE MATRICULADOS].CODCOLIGADA AND
A.CODFILIAL = [PRE MATRICULADOS].CODFILIAL AND
A.CODTURMA = [PRE MATRICULADOS].CODTURMA AND
A.IDHABILITACAOFILIAL = [PRE MATRICULADOS].IDHABILITACAOFILIAL AND
A.IDPERLET = [PRE MATRICULADOS].IDPERLET
LEFT JOIN (
SELECT
CODCOLIGADA, CODFILIAL, CODTURMA, IDHABILITACAOFILIAL, IDPERLET, COUNT(RA) AS TOTAL
FROM SMATRICPL
WHERE CODSTATUS IN (39,43,44,42,40)
GROUP BY CODCOLIGADA, CODFILIAL, CODTURMA, IDHABILITACAOFILIAL, IDPERLET
) [OUTROS] (CODCOLIGADA, CODFILIAL, CODTURMA, IDHABILITACAOFILIAL, IDPERLET, TOTAL) ON
A.CODCOLIGADA = [OUTROS].CODCOLIGADA AND
A.CODFILIAL = [OUTROS].CODFILIAL AND
A.CODTURMA = [OUTROS].CODTURMA AND
A.IDHABILITACAOFILIAL = [OUTROS].IDHABILITACAOFILIAL AND
A.IDPERLET = [OUTROS].IDPERLET
WHERE
B.CODPERLET = @CODPERLET AND A.CODFILIAL = @CODFILIAL
GROUP BY
A.CODTURMA, [PRE MATRICULADOS].TOTAL, [OUTROS].TOTAL