select distinct 
Employes.Employe.IDEmploye
,Employes.Employe.Numero
,Employes.Employe.Nom
,Employes.Employe.Prenom
,Reference.ClasseEmploi.Titre as TitrePoste
,Reference.ServiceDiscipline.Titre AS ServiceDiscipline
,Coordonnees.Telephone.Numero
,Coordonnees.Telephone.Poste
,Employes.EmployeCourriel.Courriel
,Employes.Employe.NumeroLocal
,Employes.Fonction.DateDebut
,Employes.Fonction.DateFin 
from  Employes.Employe
inner join Employes.Fonction on Employes.Employe.IDEmploye = Employes.Fonction.IDEmploye
inner join Employes.Profil on Employes.Fonction.IDFonction = Employes.Profil.IDFonction
inner join Employes.ProfilServiceDiscipline on Employes.Profil.IDProfil = Employes.ProfilServiceDiscipline.IDProfil
inner join Reference.ServiceDiscipline on Employes.ProfilServiceDiscipline.IDServiceDiscipline=  Reference.ServiceDiscipline.IDServiceDiscipline
inner join Reference.ClasseEmploi on Employes.Fonction.IDClasseEmploi =Reference.ClasseEmploi.IDClasseEmploi
left join Employes.EmployeTelephone on Employes.Employe.IDEmploye =Employes.EmployeTelephone.IDEmploye and Employes.EmployeTelephone.TypeTelephone=8
left join Coordonnees.Telephone on Employes.EmployeTelephone.IDTelephone = Coordonnees.Telephone.IDTelephone
left join Employes.EmployeCourriel on Employes.Employe.IDEmploye = Employes.EmployeCourriel.IDEmploye and Employes.EmployeCourriel.DateDesactivation is null and Employes.EmployeCourriel.TypeCourriel='STD'
WHERE (Employes.Employe.IndicateurActifCalculPaie  =1) 
and (Employes.Fonction.DateFin is null or Employes.Fonction.DateFin > getDate())
and (Employes.Profil.Sequence = (select max(p.Sequence) from Employes.Profil p where p.IDFonction = Employes.Fonction.IDFonction))
and (Employes.Fonction.DateDebut = (select max(f.DateDebut) from Employes.Fonction f where (f.DateFin is null or f.DateFin > getdate()) and f.IDEmploye = Employes.Employe.IDEmploye))
and Reference.ServiceDiscipline.Etat=1                                    
and Employes.Employe.Numero  =  07758 -- 08588 -- 07758--    09264      -- 07542 --    08527 -- 09097 --  in ( 09097,09225) -- 09097 --08837 --09230 --09041-- 07758 --  08953  
order by Employes.Employe.Nom,Employes.Employe.Prenom

						

--select
--Reference.ClasseEmploi.Titre ,
-- Employes.Employe.Numero  
--,Employes.Profil.Sequence p
--,Employes.Fonction.Sequence f
--from Employes.Employe 
--inner join Employes.Fonction on Employes.Employe.IDEmploye = Employes.Fonction.IDEmploye
--inner join Employes.Profil on Employes.Fonction.IDFonction = Employes.Profil.IDFonction
--inner join Reference.ClasseEmploi on Employes.Fonction.IDClasseEmploi =Reference.ClasseEmploi.IDClasseEmploi
--where Employes.Employe.Numero = 08527
----and Employes.Fonction.DateFin is null
--order by Employes.Fonction.DateDebut

