I am creating a sql for checkin time for employees.
My table looks like this
I want to display checkin time for employees.
So for example jason timesheet will look something like this
name | 1st feb | 2nd feb | 3rd feb
----------------------------------------------------
jason | 9:00:00 | 9:00:00 | ...
clark | ... | ... | ...
I have found a similar question here Efficiently convert rows to columns in sql server
But it's not quite working
**Updated:**following is my sql
DECLARE @cols AS NVARCHAR(MAX),
@query AS NVARCHAR(MAX)
select @cols = STUFF((SELECT ',' + QUOTENAME(checkin)
from cico
group by checkin, id
order by id
FOR XML PATH(''), TYPE
).value('.', 'NVARCHAR(MAX)')
,1,1,'')
set @query = N'SELECT ' + @cols + N' from
(
select checkin, name
from cico
) x
pivot
(
max(checkin)
for name in (' + @cols + N')
) p '
exec sp_executesql @query;
END