we are trying to convert an attendance log data into a pivot table . for the sake of simplicity, the actual data is in the form :
EmployeeId, InOrOut, DateTime
1 0 2019-01-01 08:00:00
1 1 2019-01-01 17:00:00
1 0 2019-01-02 08:00:00
1 1 2019-01-02 17:00:00
2 0 2019-01-01 08:00:00
2 1 2019-01-01 17:00:00
and we need to make it like so:
EmployeeId, Date, InTime , OutTime
1 2019-01-01 08:00 17:00
1 2019-01-02 08:00 17:00
2 2019-01-01 08:00 17:00
however the query we have made doesnt seem to work like this. the query is as under:
SELECT * FROM
(
SELECT aml.EnrollNumber, aml.A_Date, aml.InOutMode, aml.A_Time
FROM dbo.Attendence_Machines_LOG aml) AS AttendanceTable
PIVOT (
max(A_Date)
FOR InOutMode in ([1],[0])
) as PivotTable
There are many confusions regarding pivot and personally cannot find much tutorials.
how do we tell the query that on which basis is the data put in a new row (for example in this case, how will we tell the query to seperate the records according to date and employeeid)
any help appreciated