select * from (select '587' as codigo_emec, case pf.cd_nivel when 1 then pf.cd_inep else null end as curso_codigo, pf.nm_progr_form as curso_nome, case when pf.cd_nivel='1' then '1' when pf.cd_nivel in (5,8) then '3' when pf.cd_nivel in (2,6) then '4' end as curso_tipo, v.nm_cpf_pess as cpf, case when pf.cd_progr_form in (3,44,48,107,95,25,11,49,17,40,90,52,38,93,6,51,5,4,18,19,20,53,12,45,13,46,96) then '1' else '0' end as csf, case when exists (select 8 from siga_dado_hist dh1 where dh1.nu_matr_curso=v.nu_matr_curso and dh1.cd_sit_hist IN (1,7,8,9) ) then (SELECT trunc(SUM(cc.nu_carga_horr_tot) * 100 / pe.nu_carga_horr_tot, 2) FROM siga_dado_hist dh, siga_atividade_academica aa, siga_componente_curricular cc WHERE dh.nu_matr_curso = v.nu_matr_curso AND dh.cd_ativ_acad = aa.cd_ativ_acad AND aa.cd_compnt_curr = cc.cd_compnt_curr AND dh.cd_sit_hist IN (1,7,8,9) AND pe.nu_carga_horr_tot <> 0 -- BARZA ) else trunc(0,2) end AS integralidade, case when pf.cd_nivel=1 and exists (select 8 from siga_dado_hist dh1 where dh1.nu_matr_curso=v.nu_matr_curso and dh1.cd_sit_hist IN (1,3,4,5,7,8,9) and dh1.nu_media_fim > 0 ) then (SELECT trunc(SUM(dh.nu_media_fim) / count(8), 2) FROM siga_dado_hist dh, siga_atividade_academica aa, siga_componente_curricular cc WHERE dh.nu_matr_curso = v.nu_matr_curso AND dh.cd_ativ_acad = aa.cd_ativ_acad AND aa.cd_compnt_curr = cc.cd_compnt_curr AND dh.cd_sit_hist IN (1,3,4,5,7,8,9) ) else trunc(0,2) end AS media, case when p.nm_email_secd is null then 'email_nao_informado' else p.nm_email_secd end as email, case when tv.cd_turno=2 then '1' when tv.cd_turno=3 then '2' when tv.cd_turno in (4,5) then '3' when tv.cd_turno in (1,6) then '4' end as turno, '0' as bolsista_jt --,v.NU_ANO_ADMIS,v.NU_SEMTR_ADMIS -- BARZA from siga_vinculo v, siga_pessoa p, siga_programa_formacao pf, siga_turno_vinculo tv, siga_vinculo_perfil vp, siga_perfil pe where v.nm_cpf_pess=p.nm_cpf_pess and v.cd_progr_form=pf.cd_progr_form and v.nu_matr_curso=tv.nu_matr_curso and v.nu_matr_curso=vp.nu_matr_curso and vp.cd_perf=pe.cd_perf and vp.tp_perf=pe.tp_perf and v.fl_vinc='1' and pf.cd_nivel in (1,2,5,6,8) and tv.cd_perd_letv=(select max(tv1.cd_perd_letv) from siga_turno_vinculo tv1 where tv1.nu_matr_curso=tv.nu_matr_curso) and vp.cd_perd_letv=(select max(vp1.cd_perd_letv) from siga_vinculo_perfil vp1 where vp1.nu_matr_curso=vp.nu_matr_curso) and pf.cd_progr_form not in (14,15,85) -- and v.nm_cpf_pess IN ('03732225488','02312302497') and ((v.NU_ANO_ADMIS = '2015'and v.NU_SEMTR_ADMIS = '1') or ( v.NU_ANO_ADMIS = '2014'and v.NU_SEMTR_ADMIS = '2')) -- BARZA ( Apenas para os periodos letivos definidos nessa consulta) order by pf.cd_nivel, pf.nm_progr_form) where (integralidade >= 0 and integralidade < 100); -- BARZA -------------------------------------- Observação: Ao executar o script, fazer os seguintes procedimentos para gerar o arquivo conforme as especificações do Ciencia Sem Fronteira: 1 - Exportar: 1.1 - Escolher a opção -> Delimiter 1.2 - Separador -> ; (ponto e virgula) 1.3 - Retirar -> " (aspas) 1.4 - Salvar o arquivo como isf.csv 2 - Após isso, abrir o arquivo gerado (isf.csv) no bloco de notas e substituir os valores que estão em vírgulas (integralidade e media) por ponto 2.1 - Editar -> Substituir 2.2.- Salvar o arquivo 2 -