Ver Mensaje Individual
  #3 (permalink)  
Antiguo 08/04/2013, 11:15
Avatar de Libras
Libras
Colaborador
 
Fecha de Ingreso: agosto-2006
Ubicación: En la hermosa perla de occidente
Mensajes: 7.412
Antigüedad: 18 años, 4 meses
Puntos: 774
Respuesta: Horas Laboradas con SQl Server 2005

lo mismo que pense yo :P

Código SQL:
Ver original
  1. CREATE TABLE #temp
  2. (
  3. id INT,
  4. nombre VARCHAR(20),
  5. fecha DATE,
  6. entrada TIME,
  7. salida TIME
  8. )
  9.  
  10. INSERT INTO #temp VALUES (22122005,'CHAUR','04/06/2013',NULL,'13:17:23')
  11. INSERT INTO #temp VALUES (22122005,'CHAUR','04/06/2013', '06:20:21', NULL)
  12. INSERT INTO #temp VALUES (42910017,'ESCOBAR','04/06/2013', '06:27:15', NULL)
  13. INSERT INTO #temp VALUES (43114011,'CACERES','04/06/2013','06:31:12', NULL)
  14. INSERT INTO #temp VALUES (52999015,'JARAMILLO','04/06/2013', '06:08:03', NULL)
  15. INSERT INTO #temp VALUES (52999015,'JARAMILLO','04/06/2013', NULL ,'06:48:17')
  16. INSERT INTO #temp VALUES (52999015,'JARAMILLO','04/06/2013', '06:52:51', NULL)
  17. INSERT INTO #temp VALUES (63126005,'BARRERA','04/06/2013', '06:14:57', NULL)
  18. INSERT INTO #temp VALUES (92109002,'SUAREZ','04/06/2013', '06:25:34', NULL)
  19. INSERT INTO #temp VALUES (92109002,'SUAREZ','04/06/2013', NULL, '13:17:15')
  20. INSERT INTO #temp VALUES (92129008,'RODRIGUEZ','04/06/2013', '06:12:28',NULL)
  21. INSERT INTO #temp VALUES (92129008,'RODRIGUEZ','04/06/2013', NULL,'13:17:20')
  22. INSERT INTO #temp VALUES (93119011,'VEGA','04/06/2013', '06:09:14',NULL)
  23.  
  24.  
  25.  
  26. SELECT SUM(horas) horas ,SUM(minutos) minutos ,id INTO #temp2 FROM(
  27. SELECT id,DATEDIFF(hh,entrada,salida) horas,datediff(mi,entrada,salida) minutos,entrada,salida FROM(
  28. SELECT t1.id,
  29. CASE WHEN t1.entrada IS NULL THEN t2.entrada ELSE t1.entrada END AS entrada,
  30. CASE WHEN t1.salida IS NULL THEN t2.salida ELSE t1.salida END AS salida
  31. --t1.entrada,t1.salida,t2.entrada,t2.salida
  32. FROM #temp AS t1
  33. LEFT JOIN #temp AS t2 ON (t1.id=t2.id)
  34. ) AS t3 WHERE (entrada IS NOT NULL OR salida IS NOT NULL)
  35. GROUP BY id,entrada,salida
  36. ) t4 GROUP BY id
__________________
What does an execution plan say to t-sql query? Go f**k yourself, if you are not happy with me