with DaysInMonth as ( select @date as Date union all select dateadd(dd,1,Date) from DaysInMonth where month(date) = month(@Date)) select * into #TMP_DATES from DaysInMonth where month(date) = month(@Date)
DECLARE @COLUMN VARCHAR(MAX)
DECLARE @Columns2 VARCHAR(MAX)
DECLARE @QUERY VARCHAR(MAX)
SET @QUERY ='SELECT EmployeeId, ' + @Columns2 +' FROM (SELECT A.EmployeeId,MIN(CAST(A.Date as time))as intime,B.Date AS DATE FROM Att A RIGHT OUTER JOIN #TMP_DATES B ON A.Date=B.Date GROUP BY A.EmployeeId) XPIVOT (MIN([intime]) FOR [DATE] IN (' + @COLUMN + ')) P WHERE ISNULL(EmployeeId,'''')<>'''''
EXEC (@QUERY)DROP TABLE #TMP_DATESEND
I have tried this sp for display monthwise intime and outime of employee but it is getting error as