jueves, 26 de septiembre de 2013

Agrupar por Datetime en SQLserver 2005 EJEMPLO

no sabia q se podia hacer converts en el group by y si se puede!! :D

este ejemplo le quita el time al datetime para poderlo agrupar por fecha

select (select DATEADD(DAY,DATEDIFF(DAY,0,v.FechaVenta ),0))as fechaventa , min(id) as folioinicial,max(id) as foliofinal, count(impvale) as cantidad,impvale, (count(impvale)* (impvale)) as importe from vales v
where v.cliente =1
and convert(datetime,Fechaventa)  >= convert(datetime,'25/04/2013') and Fechaventa <= convert(datetime,'25-09-2013 00:00:00')
group by v.ImpVale,v.cliente,DATEADD(DAY,DATEDIFF(DAY,0,v.FechaVenta ),0)
order by v.cliente

fechaventa              folioinicial foliofinal  cantidad    impvale               importe
----------------------- ------------ ----------- ----------- --------------------- ---------------------
2013-05-09 00:00:00.000 7073         7073        1           1.00                  1.00

No hay comentarios.: