Hi, I have a table with the following data:---------------------------------------------------EmpID | AttendanceDate | TimeIN | TimeOut---------------------------------------------------1 | 2016-01-19 |08:00 AM |05:00PM 2 | 2016-01-19 |08:00 AM |05:00PM I have created a Pivot for the TimeIN, The pivot will show per date column:--------------------------------------------------------------------EmpID | 2016-01-19 | 2016-01-20 | 2016-01-21 |1 | 08:00 AM2 | 08:00 AMI would like some help because I also want to show the TimeOut per date column, I think I need to add another column, so per day, there would be two columns one is for IN and one is for OUT with the date. My code is : [quote]DECLARE @cols AS NVARCHAR(MAX), @query AS NVARCHAR(MAX)select @cols = STUFF((SELECT ',' + QUOTENAME(convert(char(10), AttendanceDate, 120)) from AttendanceMovement --where AttendanceDate='2016-01-01' group by AttendanceDate order by AttendanceDate asc FOR XML PATH(''), TYPE ).value('.', 'NVARCHAR(MAX)') ,1,1,'')set @query = 'SELECT EmployeeID ,' + @cols + ' from ( select EmployeeID,Sched1TimeIn flag,AttendanceDate from AttendanceMovement ) x pivot ( max(flag) for AttendanceDate in (' + @cols + ') ) p 'execute(@query)[/quote]
↧