SELECT
 (T_SAL.MatriculeSalarie + ' ' + isnull(T_SAL.Nom, '') + ' '  + isnull(T_SAL.Prenom, '') ) as Col1,
 'Date de fin d''absence : '+ CONVERT(VARCHAR(12),T_GHRSAL.PeriodeFin, 113) as Col2 
FROM
  T_PAI,
  T_SAL
  LEFT OUTER JOIN T_GHRSAL ON T_GHRSAL.NumSalarie=T_SAL.SA_CompteurNumero
WHERE (  DatePart(mm, T_GHRSAL.PeriodeFin) = ISNULL (NULLIF((T_PAI.MoisEnCours - ISNULL(%Mois%,0)),0),12) 
         and ( ( DatePart(yyyy, T_GHRSAL.PeriodeFin) = T_PAI.AnneeEnCours - 1
                 AND (ISNULL(NULLIF((T_PAI.MoisEnCours - ISNULL(%Mois%,0)),0),12) = 12
                      AND ISNULL(%Mois%,0) = 1)
                )
                OR
                ( DatePart(yyyy, T_GHRSAL.PeriodeFin) = T_PAI.AnneeEnCours
                 AND (ISNULL(NULLIF((T_PAI.MoisEnCours - ISNULL(%Mois%,0)),0),12) <> 12
                      OR ISNULL(%Mois%,0) = 0)
                 )
              )
		  and (T_GHRSAL.CodeNE = isnull(%NatureAbsence1%,0) 
               OR T_GHRSAL.CodeNE = isnull(%NatureAbsence2%,0) 
               OR T_GHRSAL.CodeNE = isnull(%NatureAbsence3%,0))
       )
Order by T_SAL.MatriculeSalarie, T_GHRSAL.CodeNE
