Ver Mensaje Individual
  #6  
Antiguo 04-01-2007
Avatar de fjcg02
[fjcg02] fjcg02 is offline
Miembro Premium
 
Registrado: dic 2003
Ubicación: Zamudio
Posts: 1.410
Reputación: 22
fjcg02 Va camino a la fama
Creo que con esto podrás visualizar en un db grid los datos que necesitas.

Qué hace: El case mira que el mes de la fecha sea 1, 2, 3, ...12 para ajustar a la columna correspondiente la cantidad.
Si se cumple, suma el valor del campo que nos ocupa (efectivo, credito, tarjeta) y lo suma. Si no, suma 0

Hacemos una union de los tres tipos de venta y tenemos todo perfecto.

Puede que hay que ajustar algo ya que no tengo SQL Server ni analizador de SQL, pero algo tendrás que hacer tú ;.) ...
Además tendrás que parametrizar la query para que las fechas las puedas poner por Tedit o similar

Suerte


Código SQL [-]
select 'Ventas Efectivo' as TipoVenta, 
sum( case datepart("month", fecha_venta) when 1 then Venta_Efectivo else 0 end) as Enero,
sum( case datepart("month", fecha_venta) when 2 then Venta_Efectivo else 0 end) as Febrero,
sum( case datepart("month", fecha_venta) when 3 then Venta_Efectivo else 0 end) as Marzo,
sum( case datepart("month", fecha_venta) when 4 then Venta_Efectivo else 0 end) as Abril,
sum( case datepart("month", fecha_venta) when 5 then Venta_Efectivo else 0 end) as Mayo,
sum( case datepart("month", fecha_venta) when 6 then Venta_Efectivo else 0 end) as Junio,
sum( case datepart("month", fecha_venta) when 7 then Venta_Efectivo else 0 end) as Julio,
sum( case datepart("month", fecha_venta) when 8 then Venta_Efectivo else 0 end) as Agosto,
sum( case datepart("month", fecha_venta) when 9 then Venta_Efectivo else 0 end) as Septiembre,
sum( case datepart("month", fecha_venta) when 10 then Venta_Efectivo else 0 end) as Octubre,
sum( case datepart("month", fecha_venta) when 11 then Venta_Efectivo else 0 end) as Noviembre,
sum( case datepart("month", fecha_venta) when 12 then Venta_Efectivo else 0 end) as Diciembre 
FROM ahd.tareas
where 
fecha_venta between '01/01/2006' and '12/31/2006' 
group by tipoventa

UNION

select 'Ventas Credito' as TipoVenta, 
sum( case datepart("month", fecha_venta) when 1 then Venta_Credito else 0 end) as Enero,
sum( case datepart("month", fecha_venta) when 2 then Venta_Credito else 0 end) as Febrero,
sum( case datepart("month", fecha_venta) when 3 then Venta_Credito else 0 end) as Marzo,
sum( case datepart("month", fecha_venta) when 4 then Venta_Credito else 0 end) as Abril,
sum( case datepart("month", fecha_venta) when 5 then Venta_Credito else 0 end) as Mayo,
sum( case datepart("month", fecha_venta) when 6 then Venta_Credito else 0 end) as Junio,
sum( case datepart("month", fecha_venta) when 7 then Venta_Credito else 0 end) as Julio,
sum( case datepart("month", fecha_venta) when 8 then Venta_Credito else 0 end) as Agosto,
sum( case datepart("month", fecha_venta) when 9 then Venta_Credito else 0 end) as Septiembre,
sum( case datepart("month", fecha_venta) when 10 then Venta_Credito else 0 end) as Octubre,
sum( case datepart("month", fecha_venta) when 11 then Venta_Credito else 0 end) as Noviembre,
sum( case datepart("month", fecha_venta) when 12 then Venta_Credito else 0 end) as Diciembre 
FROM ahd.tareas
where 
fecha_venta between '01/01/2006' and '12/31/2006' 
group by tipoventa

UNION

select 'Ventas Tarjeta' as TipoVenta, 
sum( case datepart("month", fecha_venta) when 1 then Venta_Tarjeta else 0 end) as Enero,
sum( case datepart("month", fecha_venta) when 2 then Venta_Tarjeta else 0 end) as Febrero,
sum( case datepart("month", fecha_venta) when 3 then Venta_Tarjeta else 0 end) as Marzo,
sum( case datepart("month", fecha_venta) when 4 then Venta_Tarjeta else 0 end) as Abril,
sum( case datepart("month", fecha_venta) when 5 then Venta_Tarjeta else 0 end) as Mayo,
sum( case datepart("month", fecha_venta) when 6 then Venta_Tarjeta else 0 end) as Junio,
sum( case datepart("month", fecha_venta) when 7 then Venta_Tarjeta else 0 end) as Julio,
sum( case datepart("month", fecha_venta) when 8 then Venta_Tarjeta else 0 end) as Agosto,
sum( case datepart("month", fecha_venta) when 9 then Venta_Tarjeta else 0 end) as Septiembre,
sum( case datepart("month", fecha_venta) when 10 then Venta_Tarjeta else 0 end) as Octubre,
sum( case datepart("month", fecha_venta) when 11 then Venta_Tarjeta else 0 end) as Noviembre,
sum( case datepart("month", fecha_venta) when 12 then Venta_Tarjeta else 0 end) as Diciembre 
FROM ahd.tareas
where 
fecha_venta between '01/01/2006' and '12/31/2006' 
group by tipoventa
__________________
Cuando los grillos cantan, es que es de noche - viejo proverbio chino -
Responder Con Cita