Foros del Web » Programación para mayores de 30 ;) » Bases de Datos General » SQL Server »

agrupar por hora o devolver la hora de una fecha

Estas en el tema de agrupar por hora o devolver la hora de una fecha en el foro de SQL Server en Foros del Web. holas tengo un campo de tipo datetime y necesito trabajar solo con la hora de un registro, es posible hacerlo??? como si se usara la ...
  #1 (permalink)  
Antiguo 04/09/2006, 11:31
Avatar de Rocket  
Fecha de Ingreso: diciembre-2001
Ubicación: Santiago, Chile
Mensajes: 272
Antigüedad: 22 años, 4 meses
Puntos: 4
Pregunta agrupar por hora o devolver la hora de una fecha

holas
tengo un campo de tipo datetime y necesito trabajar solo con la hora de un registro, es posible hacerlo??? como si se usara la funcion year, day o month

saludos
  #2 (permalink)  
Antiguo 04/09/2006, 15:00
 
Fecha de Ingreso: agosto-2006
Mensajes: 7
Antigüedad: 17 años, 8 meses
Puntos: 0
Devolver la Hora

Por medio de esta instucción te devuelve la hora de un datetime:
CONVERT(nvarchar(8), GETDATE(), 108)
  #3 (permalink)  
Antiguo 05/09/2006, 08:33
Avatar de Rocket  
Fecha de Ingreso: diciembre-2001
Ubicación: Santiago, Chile
Mensajes: 272
Antigüedad: 22 años, 4 meses
Puntos: 4
gracias
me funciona para el select pero como podria agruparlos por la hora?
  #4 (permalink)  
Antiguo 05/09/2006, 08:39
Avatar de Andres95
Colaborador
 
Fecha de Ingreso: diciembre-2004
Mensajes: 1.802
Antigüedad: 19 años, 4 meses
Puntos: 38
-- Al final
Group by CONVERT(nvarchar(8), GETDATE(), 108)


-- Solo reemplaza getdate por tu campo, quedaria igual que en tu clausula select
  #5 (permalink)  
Antiguo 05/09/2006, 08:48
Avatar de Rocket  
Fecha de Ingreso: diciembre-2001
Ubicación: Santiago, Chile
Mensajes: 272
Antigüedad: 22 años, 4 meses
Puntos: 4
mmm
pero eso no funciona
  #6 (permalink)  
Antiguo 05/09/2006, 09:03
Avatar de Andres95
Colaborador
 
Fecha de Ingreso: diciembre-2004
Mensajes: 1.802
Antigüedad: 19 años, 4 meses
Puntos: 38
que resultado obtienes?? un error?
  #7 (permalink)  
Antiguo 05/09/2006, 09:10
Avatar de Rocket  
Fecha de Ingreso: diciembre-2001
Ubicación: Santiago, Chile
Mensajes: 272
Antigüedad: 22 años, 4 meses
Puntos: 4
sip, este es el sql

SELECT CONVERT(nvarchar(2), dFecha, 108), count(id) as cantidad
FROM Error500_Detalle
WHERE day(dFecha) = 5 and month(dFecha) = 9 and year(dFecha) = 2006
GROUP BY CONVERT(nvarchar(8), dFecha, 108)
ORDER BY year(dFecha), month(dFecha), day(dFecha)

y este es el error
Column 'Error500_Detalle.dFecha' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.
Column name 'Error500_Detalle.dFecha' is invalid in the ORDER BY clause because it is not contained in either an aggregate function or the GROUP BY clause.
  #8 (permalink)  
Antiguo 05/09/2006, 09:14
Avatar de Andres95
Colaborador
 
Fecha de Ingreso: diciembre-2004
Mensajes: 1.802
Antigüedad: 19 años, 4 meses
Puntos: 38
brother te comentaba que el group by quedaria igual que en el select...
en este caso...

Group by CONVERT(nvarchar(2), dFecha, 108)
  #9 (permalink)  
Antiguo 05/09/2006, 09:15
Avatar de Rocket  
Fecha de Ingreso: diciembre-2001
Ubicación: Santiago, Chile
Mensajes: 272
Antigüedad: 22 años, 4 meses
Puntos: 4
me ekivoke al postearlo, ahi lo corregi
  #10 (permalink)  
Antiguo 05/09/2006, 09:20
Avatar de Andres95
Colaborador
 
Fecha de Ingreso: diciembre-2004
Mensajes: 1.802
Antigüedad: 19 años, 4 meses
Puntos: 38
Cita:
Iniciado por Rocket Ver Mensaje
me ekivoke al postearlo, ahi lo corregi
no te entendi....
----------------------------
Ah ok...

has el select sin el order by tal vez ahi este el error
  #11 (permalink)  
Antiguo 05/09/2006, 09:23
Avatar de Rocket  
Fecha de Ingreso: diciembre-2001
Ubicación: Santiago, Chile
Mensajes: 272
Antigüedad: 22 años, 4 meses
Puntos: 4
ya encontre el error,el parametro del nvarchar()
ahora funciona

muchas gracias por tu tiempo
  #12 (permalink)  
Antiguo 05/09/2006, 09:26
Avatar de Andres95
Colaborador
 
Fecha de Ingreso: diciembre-2004
Mensajes: 1.802
Antigüedad: 19 años, 4 meses
Puntos: 38


un saludo
  #13 (permalink)  
Antiguo 06/10/2009, 10:27
Avatar de Salvadri  
Fecha de Ingreso: agosto-2009
Mensajes: 45
Antigüedad: 14 años, 8 meses
Puntos: 0
Respuesta: agrupar por hora o devolver la hora de una fecha

Se veia el error a leguas, si el time te devuelve 8, el nvarchar(2) jamas iba aceptar....
  #14 (permalink)  
Antiguo 06/10/2009, 10:36
Avatar de Andres95
Colaborador
 
Fecha de Ingreso: diciembre-2004
Mensajes: 1.802
Antigüedad: 19 años, 4 meses
Puntos: 38
Respuesta: agrupar por hora o devolver la hora de una fecha

Cita:
Iniciado por Salvadri Ver Mensaje
Se veia el error a leguas, si el time te devuelve 8, el nvarchar(2) jamas iba aceptar....
Tratemos de hacer comentarios que aporten algo de utilidad.



Saludos!
__________________
La sencillez y naturalidad son el supremo y último fin de la cultura...
--
MCTS : SQL Server 2008, .NET Framework 3.5, ASP.NET Applications.
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 04:46.