ALTER PROCEDURE dbo.QSubPFrm1_CloseShift
  @StartDateList NVARCHAR(10),
  @EndDateList   NVARCHAR(10)
AS

SELECT        COUNT(T_Forosh.FOROSHID) AS Expr1, T_Forosh.DateFo, T_Forosh.Flag1, AC_Setting.dbo.T_yUsers.FullName
FROM            T_Forosh LEFT OUTER JOIN
                         AC_Setting.dbo.T_yUsers ON T_Forosh.UserID = AC_Setting.dbo.T_yUsers.USERID LEFT OUTER JOIN
                         T_SA2 ON T_Forosh.PrimarySaid2 = T_SA2.SAID2
WHERE        (T_SA2.FieldN2 = 26) AND (NOT (T_Forosh.UserID IS NULL)) AND (T_Forosh.DateFo BETWEEN @StartDateList AND @EndDateList) OR
                         (T_SA2.FieldN2 IS NULL) AND (NOT (T_Forosh.UserID IS NULL)) AND (T_Forosh.DateFo BETWEEN @StartDateList AND @EndDateList) AND (T_Forosh.Flag1 = 0)
GROUP BY T_Forosh.DateFo, T_Forosh.Flag1, AC_Setting.dbo.T_yUsers.FullName
ORDER BY T_Forosh.DateFo DESC, T_Forosh.Flag1


GO