Use Common Table Expression (CTE) above Select Statement. In select query, you have to do join with #Tempshift and then will calculate the shift.
This CTE computes attendance information for each employee, grouped by date and shift, with the calculated "In-Time" and "Out-Time" for each shift.