Hola erasmorc.
Compaginé tu código en este mensaje, por que como está en el primero es imposible de leer para quién no sea un criptógrafo avezado.
Código SQL
[-]
select CodigoCliente, sum(totalfactura) TotalFactura,
case when datediff(d,fechafactura,'13/06/2012') BETWEEN 0 and 30 then TotalFacturaend '1-30',
case when datediff(d,fechafactura,'13/06/2012') BETWEEN 31 and 60 then TotalFacturaend '31-60',
case when datediff(d,fechafactura,'13/06/2012') BETWEEN 61 and 90 then TotalFacturaend '61-90',
case when datediff(d,fechafactura,'13/06/2012') BETWEEN 91 and 9999 then TotalFactura '91 o Mas'
end
from encfactura
where year(fechafactura)= 2012
group by CodigoCliente,
case when datediff(d,fechafactura,'13/06/2012') BETWEEN 0 and 30 then Total Facturaend,
case when datediff(d,fechafactura,'13/06/2012') BETWEEN 31 and 60 then TotalFacturaend,
case when datediff(d,fechafactura,'13/06/2012') BETWEEN 61 and 90 then TotalFacturaend,
case when datediff(d,fechafactura,'13/06/2012') BETWEEN 91 and 9999 then TotalFactura
end
order by CodigoCliente
Si me equivoqué en algo al transcribir, hazmelo saber y lo corrigo.
Es por eso que insistimos tanto con las etiquetas...
Saludos.