Ver Mensaje Individual
  #2 (permalink)  
Antiguo 14/08/2014, 15:16
Avatar de Libras
Libras
Colaborador
 
Fecha de Ingreso: agosto-2006
Ubicación: En la hermosa perla de occidente
Mensajes: 7.412
Antigüedad: 17 años, 8 meses
Puntos: 774
Respuesta: Sumar horas con criterio en comun

Código SQL:
Ver original
  1. CREATE TABLE #temp
  2. (
  3. campo1 VARCHAR(20),
  4. campo2 VARCHAR(20)
  5. )
  6.  
  7. INSERT INTO #temp VALUES ('S_YOMBLON','00:04:55')
  8. INSERT INTO #temp VALUES ('S_YOMBLON','01:16:55')
  9. INSERT INTO #temp VALUES ('S_YOMBLON','07:10:15')
  10. INSERT INTO #temp VALUES ('S_YOMBLON','07:12:45')
  11. INSERT INTO #temp VALUES ('S_YOMBLON','07:24:30')
  12. INSERT INTO #temp VALUES ('S_YOMBLON','07:29:38')
  13. INSERT INTO #temp VALUES ('S_YOMBLON','07:31:58')
  14. INSERT INTO #temp VALUES ('S_YOMBLON','07:34:50')
  15. INSERT INTO #temp VALUES ('S_YOMBLON','07:41:30')
  16.  
  17.  
  18. SELECT campo1,
  19.     RIGHT(100+SUM(CAST(PARSENAME(REPLACE(campo2,':','.'),3) AS INT))
  20.            +SUM((CAST(PARSENAME(REPLACE(campo2,':','.'),2) AS INT)
  21.            +CAST(PARSENAME(REPLACE(campo2,':','.'),1) AS INT)))/60,2)
  22.     +':'
  23.     +RIGHT(100+SUM((CAST(PARSENAME(REPLACE(campo2,':','.'),2) AS INT)
  24.            +CAST(PARSENAME(REPLACE(campo2,':','.'),1) AS INT)))%60,2)
  25.     +':'
  26.     +RIGHT(100+SUM(CAST(PARSENAME(REPLACE(campo2,':','.'),1) AS INT))%60,2)
  27. FROM #temp GROUP BY campo1

Busquele en google:
http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=121027
__________________
What does an execution plan say to t-sql query? Go f**k yourself, if you are not happy with me