Code:
;with cte as ( select empid, cast(datepart(hh, logtime) as varchar(2)) + ':' + right('0' + cast(datepart(mi, logtime) as varchar(2)), 2) as logtime, row_number() over (partition by empid order by logid) as row from #timing ) select c1.empid as EmployeeID, min(c1.logtime) as InTime, max(c2.logtime) as OutTime, min(isnull(p.punches, '')) as Punches from cte c1 join cte c2 on c1.row + 1 = c2.row and c1.empid = c2.empid left join ( select empid, (select '(' + stuff( (select ', ' +c1.logtime + ' In, ' + c2.logtime + ' Out' from cte c1 join cte c2 on c1.row + 1 = c2.row and c1.empid = c2.empid where c1.row % 2 = 1 and c3.empid = c1.empid for xml path(''), type).value('text()[1]','varchar(max)'), 1, 2, '') + ')' ) as punches from cte c3 group by empid ) as p on p.empid = c1.empid group by c1.empid order by c1.empid
How Can I use this query into stored procedure..?
my stored Procedure Name is spReportPunchRe cord and has no parameter pass.
thanks in advance.
Comment