actualmente estoy teniendo problemas para cargar esta informacion, ya que es bastante lento y al parecer el problema es mi consulta.
mi pregunta es como puedo otimizar los tiempos de carga en esta consulta.
SELECT distinct T0.emp_pin, T0.emp_firstname, CONVERT(date, T1.punch_time, 4) AS Fecha, CONVERT(varchar,
(SELECT MIN(punch_time) AS Expr1
FROM dbo.att_punches AS TX
WHERE (employee_id = T0.id) AND (CONVERT(date, punch_time, 1) = CONVERT(date, T1.punch_time, 1))), 24) AS Entrada,
CONVERT(varchar,
(SELECT MAX(punch_time) AS Expr1
FROM dbo.att_punches AS TX
WHERE (employee_id = T0.id) AND (CONVERT(date, punch_time, 1) = CONVERT(date, T1.punch_time, 1))), 24) AS Salida,
CONVERT(varchar,
(SELECT MIN(punch_time) AS Expr1
FROM dbo.att_punches AS TX
WHERE DATEPART(HOUR,punch_time) * 100 + DATEPART(minute,punch_time) between 1145 and 1230 and (employee_id = T0.id) AND (CONVERT(date, punch_time, 1) = CONVERT(date, T1.punch_time, 1))), 24) AS Salida_Almuerzo,
CONVERT(varchar,
(SELECT MAX(punch_time) AS Expr1
FROM dbo.att_punches AS TX
WHERE DATEPART(HOUR,punch_time) * 100 + DATEPART(minute,punch_time) between 1250 and 1330 and (employee_id = T0.id) AND (CONVERT(date, punch_time, 1) = CONVERT(date, T1.punch_time, 1))), 24) AS Entrada_Almuerzo
FROM dbo.hr_employee AS T0 LEFT JOIN
dbo.att_punches AS T1 ON T0.id = t1.employee_id
GO