SELECT CAST(COUNT(*) as nvarchar(5)) + ' salarié(s) actifs' as Col1, 
       (SELECT CAST(COUNT(*) as nvarchar(5)) 
        FROM T_PAI, T_SAL             
             INNER JOIN T_HST_INFOSSOCIETE ON T_HST_INFOSSOCIETE.NumSalarie=T_SAL.SA_CompteurNumero AND T_HST_INFOSSOCIETE.InfoEnCours=1
          
        WHERE DatePart(mm, T_HST_INFOSSOCIETE.DateEmbauche) = T_PAI.MoisEnCours
              and DatePart(yyyy, T_HST_INFOSSOCIETE.DateEmbauche) = T_PAI.AnneeEnCours )
 + ' entrée(s) / ' +      
       (SELECT CAST(COUNT(*) as nvarchar(5)) 
        FROM T_PAI,T_SAL             
             INNER JOIN T_HST_INFOSSOCIETE ON T_HST_INFOSSOCIETE.NumSalarie=T_SAL.SA_CompteurNumero AND T_HST_INFOSSOCIETE.InfoEnCours=1                     
        WHERE DatePart(mm, T_HST_INFOSSOCIETE.DateDepart) = T_PAI.MoisEnCours
              and DatePart(yyyy, T_HST_INFOSSOCIETE.DateDepart) = T_PAI.AnneeEnCours ) 
+ ' sortie(s) / ' +
        (SELECT CAST(COUNT(*) as nvarchar(5)) 
        FROM T_SAL             
             INNER JOIN T_HST_ETABLISSEMENT ON T_HST_ETABLISSEMENT.NumSalarie=T_SAL.SA_CompteurNumero AND T_HST_ETABLISSEMENT.InfoEnCours=1                             
        WHERE (T_SAL.EtatPaie IN (1, 2)) AND (ISNULL(T_HST_ETABLISSEMENT.MiseEnSommeil,0) = 1))
+ ' en sommeil' as Col2
FROM T_SAL 
     INNER JOIN T_HST_ETABLISSEMENT ON T_HST_ETABLISSEMENT.NumSalarie=T_SAL.SA_CompteurNumero AND T_HST_ETABLISSEMENT.InfoEnCours=1                             

WHERE (NOT T_SAL.EtatPaie IN (0, 5, 7)) AND (ISNULL(T_HST_ETABLISSEMENT.MiseEnSommeil,0) <> 1)

UNION
SELECT 'Bulletins  édités : ' + CAST(COUNT(*) as nvarchar(5)) as Col1, 
       '  ' as Col2
FROM T_SAL WHERE T_SAL.EtatPaie = 3
UNION
SELECT 'Bulletins à préparer : ' + CAST(COUNT(*) as nvarchar(5)) as Col1, 
        '  ' as Col2
FROM T_SAL 
     INNER JOIN T_HST_ETABLISSEMENT ON T_HST_ETABLISSEMENT.NumSalarie=T_SAL.SA_CompteurNumero AND T_HST_ETABLISSEMENT.InfoEnCours=1                             
WHERE (T_SAL.EtatPaie IN (1, 2)) AND (ISNULL(T_HST_ETABLISSEMENT.MiseEnSommeil,0) <> 1)

