SHARE
TWEET

Untitled

a guest Jun 26th, 2019 72 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. SELECT
  2.     am.CDU_Aluno AS AlunoMatricula,
  3.     amd.CDU_Aluno AS AlunoDisciplina,
  4.     am.CDU_NumInscricao AS InscricaoMatricula,
  5.     --amd.CDU_NumInscricao AS InscricaoDisciplina,
  6.     s.CDU_Situacao as 'SituacaoMatricula',
  7.     s.CDU_Descricao as 'DescricaoSituacaoMatricula',
  8.     s.CDU_Activo as 'Matricula Ativa',
  9.     am.CDU_AnoLectivo AS AnoLetivoMatricula,
  10.     --amd.CDU_AnoLectivo AS AnoLetivoDisciplina,
  11.     am.CDU_AnoGrau AS AnoGrauMatricula,
  12.     amd.CDU_AnoGrau AS AnoGrauDisciplina,
  13.     cast((CASE WHEN isnull(am.CDU_AnoGrau,'')<> isnull(amd.CDU_AnoGrau,'') THEN 1 ELSE 0 END) as bit) 'AnoGrauInvalido',
  14.     am.CDU_Curso AS CursoMatricula,
  15.     amd.CDU_Curso AS CursoDisciplina,
  16.     cast((CASE WHEN isnull(am.CDU_Curso,'')<> isnull(amd.CDU_Curso,'') THEN 1 ELSE 0 END) as bit) 'CursoInvalido',
  17.     amd.CDU_Disciplina AS Disciplina,
  18.     td.CDU_Disciplina AS DisciplinaTurmaDisciplina,
  19.     cast
  20.     (
  21.         (CASE WHEN (am.CDU_Turma is not null) AND isnull(amd.CDU_Disciplina,'')<> isnull(td.CDU_Disciplina,'') THEN 1 ELSE 0 END) as bit
  22.     ) 'DisciplinaInvalida',
  23.     am.CDU_Turma AS TurmaMatricula,
  24.     t.CDU_Turma AS Turma,
  25.     t.CDU_AnoGrau AS AnoGrauTurma,
  26.     t.CDU_AnoLectivo AS AnoLetivoTurma,
  27.     t.CDU_Curso AS CursoTurma,
  28.     td.CDU_AnoLectivo AS AnoLetivoTurmaDisciplina,
  29.     td.CDU_AnoGrau AS AnoGrauTurmaDisciplina,
  30.     td.CDU_Turma AS TrumaTurmaDisciplina
  31. FROM
  32.     TDU_AlunoMatriculas am WITH(NOLOCK)
  33.     LEFT JOIN TDU_AlunoMatriculaDisciplinas amd WITH(NOLOCK)
  34.         ON am.CDU_NumInscricao = amd.CDU_NumInscricao AND am.CDU_Aluno = amd.CDU_Aluno AND am.CDU_AnoLectivo = amd.CDU_AnoLectivo
  35.     LEFT JOIN TDU_TurmaAlunos ta WITH(NOLOCK)
  36.         ON ta.CDU_AnoLectivo = am.CDU_AnoLectivo AND ta.CDU_AnoGrau = amd.CDU_AnoGrau AND ta.CDU_Aluno = am.CDU_Aluno
  37.     LEFT JOIN TDU_TurmaDisciplinas td WITH(NOLOCK)
  38.         ON td.CDU_AnoLectivo = amd.CDU_AnoLectivo AND td.CDU_AnoGrau = amd.CDU_AnoGrau AND td.CDU_Disciplina = amd.CDU_Disciplina and td.CDU_Turma = ta.CDU_Turma
  39.     LEFT JOIN TDU_Turmas t WITH(NOLOCK) ON
  40.         am.CDU_AnoLectivo = t.CDU_AnoLectivo AND t.CDU_Turma = td.CDU_Turma
  41.     LEFT JOIN TDU_Situacoes s WITH(NOLOCK) ON
  42.         s.CDU_Situacao = am.CDU_Situacao
  43.     WHERE
  44.         am.CDU_AnoLectivo = '2018/2019'
  45.         --and am.CDU_Aluno = '3442'
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top