Ver Mensaje Individual
  #4 (permalink)  
Antiguo 26/10/2011, 11:19
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, 3 meses
Puntos: 774
Respuesta: Como puedo sacar los dias laborados de mis usuarios

Código SQL:
Ver original
  1. CREATE TABLE #temp
  2. (
  3. dia datetime,
  4. nombre VARCHAR(20)
  5. )
  6.  
  7. INSERT INTO #temp VALUES(
  8.  
  9. INSERT INTO #temp VALUES('2011-10-24 00:00:00.000','asilva')
  10. INSERT INTO #temp VALUES('2011-10-24 00:00:00.000','asilva')
  11. INSERT INTO #temp VALUES('2011-10-24 00:00:00.000','asilva')
  12. INSERT INTO #temp VALUES('2011-10-24 00:00:00.000','jguerrero')
  13. INSERT INTO #temp VALUES('2011-10-26 00:00:00.000','jguerrero')
  14. INSERT INTO #temp VALUES('2011-10-24 00:00:00.000','jguerrero')
  15. INSERT INTO #temp VALUES('2011-10-26 00:00:00.000','jguerrero')
  16. INSERT INTO #temp VALUES('2011-10-26 00:00:00.000','privera')
  17. INSERT INTO #temp VALUES('2011-10-26 00:00:00.000','privera')
  18. INSERT INTO #temp VALUES('2011-10-26 00:00:00.000','privera')
  19. INSERT INTO #temp VALUES('2011-10-24 00:00:00.000','privera')
  20. INSERT INTO #temp VALUES('2011-10-24 00:00:00.000','privera')
  21. INSERT INTO #temp VALUES('2011-10-24 00:00:00.000','privera')
  22. INSERT INTO #temp VALUES('2011-10-24 00:00:00.000','privera')
  23. INSERT INTO #temp VALUES('2011-10-24 00:00:00.000','privera')
  24. INSERT INTO #temp VALUES('2011-10-24 00:00:00.000','privera')
  25. INSERT INTO #temp VALUES('2011-10-24 00:00:00.000','privera')
  26. INSERT INTO #temp VALUES('2011-10-24 00:00:00.000','psalcedo')
  27. INSERT INTO #temp VALUES('2011-10-24 00:00:00.000','psalcedo')
  28. INSERT INTO #temp VALUES('2011-10-24 00:00:00.000','psalcedo')
  29.  
  30. SELECT COUNT(nombre) AS dias,nombre FROM
  31. (SELECT dia, nombre FROM #temp GROUP BY dia,nombre) t1 WHERE t1.dia BETWEEN '2011-10-01' AND '2011-10-30'
  32. GROUP BY nombre

Saludos!
__________________
What does an execution plan say to t-sql query? Go f**k yourself, if you are not happy with me