Facturación cliente por meses

Hola @IvanFor ya llevas un tiempo por aquí… para formatear adecuadamente el texto de los mensajes… cuando pones un código sql se usa el preformateado…

Cuando estas escribiendo… justo encima aparecen una cantidad importante de iconos que cada uno tiene una función o labor…

He tecleado “ventas meses” en el cuadro de buscar y luego apretado la lupa de buscar
En los resultados
Primera entrada al buscar
Segunda entrada
Otra entrada similar
La famosa del PIVOT

Aquí te pego un código sql de alguna de esas…

declare @fechainicio datetime, @fechafin datetime 
set @fechainicio=(/*select top 1 A.DocDate from OINV A where A.DocDate=*/'[%0]')        
set @fechafin=(/*select top 1 A.DocDate from OINV A where A.DocDate=*/'[%1]')    

Select 

((select SUM(T0.DocTotal-T0.Vatsum-T0.[TotalExpns])
FROM OINV T0 
WHERE T0.CANCELED = 'N' and T0.DocDate between @fechainicio and @fechafin
AND Month(T0.DocDate) <=1)
+ 
(select  SUM((T1.DocTotal-T1.Vatsum-T1.[TotalExpns])*-1) 
 FROM ORIN T1 
WHERE T1.CANCELED = 'N' and T1.DocDate between @fechainicio and @fechafin 
AND Month(T1.DocDate) <=1))
 as 'Enero',

((select SUM(T0.DocTotal-T0.Vatsum-T0.[TotalExpns])
FROM OINV T0 
WHERE T0.CANCELED = 'N' and T0.DocDate between @fechainicio and @fechafin
AND Month(T0.DocDate) <=2)
+ 
(select  SUM((T1.DocTotal-T1.Vatsum-T1.[TotalExpns])*-1) 
 FROM ORIN T1 
WHERE T1.CANCELED = 'N' and T1.DocDate between @fechainicio and @fechafin 
AND Month(T1.DocDate) <=2)
) as 'FEBRERO',

((select SUM(T0.DocTotal-T0.Vatsum-T0.[TotalExpns])
FROM OINV T0 
WHERE T0.CANCELED = 'N' and T0.DocDate between @fechainicio and @fechafin
AND Month(T0.DocDate) <=3)
+ 
(select  SUM((T1.DocTotal-T1.Vatsum-T1.[TotalExpns])*-1) 
 FROM ORIN T1 
WHERE T1.CANCELED = 'N' and T1.DocDate between @fechainicio and @fechafin 
AND Month(T1.DocDate) <=3)
) as 'MARZO',

((select SUM(T0.DocTotal-T0.Vatsum-T0.[TotalExpns])
FROM OINV T0 
WHERE T0.CANCELED = 'N' and T0.DocDate between @fechainicio and @fechafin
AND Month(T0.DocDate) <=4)
+ 
(select  SUM((T1.DocTotal-T1.Vatsum-T1.[TotalExpns])*-1) 
 FROM ORIN T1 
WHERE T1.CANCELED = 'N' and T1.DocDate between @fechainicio and @fechafin 
AND Month(T1.DocDate) <=4)
) as 'Abril',

((select SUM(T0.DocTotal-T0.Vatsum-T0.[TotalExpns])
FROM OINV T0 
WHERE T0.CANCELED = 'N' and T0.DocDate between @fechainicio and @fechafin
AND Month(T0.DocDate) <=5)
+ 
(select  SUM((T1.DocTotal-T1.Vatsum-T1.[TotalExpns])*-1) 
 FROM ORIN T1 
WHERE T1.CANCELED = 'N' and T1.DocDate between @fechainicio and @fechafin 
AND Month(T1.DocDate) <=5)
) as 'Mayo',

((select SUM(T0.DocTotal-T0.Vatsum-T0.[TotalExpns])
FROM OINV T0 
WHERE T0.CANCELED = 'N' and T0.DocDate between @fechainicio and @fechafin
AND Month(T0.DocDate) <=6)
+ 
(select  SUM((T1.DocTotal-T1.Vatsum-T1.[TotalExpns])*-1) 
 FROM ORIN T1 
WHERE T1.CANCELED = 'N' and T1.DocDate between @fechainicio and @fechafin 
AND Month(T1.DocDate) <=6)
) as 'Junio',


((select SUM(T0.DocTotal-T0.Vatsum-T0.[TotalExpns])
FROM OINV T0 
WHERE T0.CANCELED = 'N' and T0.DocDate between @fechainicio and @fechafin
AND Month(T0.DocDate) <=7)
+ 
(select  SUM((T1.DocTotal-T1.Vatsum-T1.[TotalExpns])*-1) 
 FROM ORIN T1 
WHERE T1.CANCELED = 'N' and T1.DocDate between @fechainicio and @fechafin 
AND Month(T1.DocDate) <=7)
) as 'Julio',


((select SUM(T0.DocTotal-T0.Vatsum-T0.[TotalExpns])
FROM OINV T0 
WHERE T0.CANCELED = 'N' and T0.DocDate between @fechainicio and @fechafin
AND Month(T0.DocDate) <=8)
+ 
(select  SUM((T1.DocTotal-T1.Vatsum-T1.[TotalExpns])*-1) 
 FROM ORIN T1 
WHERE T1.CANCELED = 'N' and T1.DocDate between @fechainicio and @fechafin 
AND Month(T1.DocDate) <=8)
) as 'Agosto',

((select SUM(T0.DocTotal-T0.Vatsum-T0.[TotalExpns])
FROM OINV T0 
WHERE T0.CANCELED = 'N' and T0.DocDate between @fechainicio and @fechafin
AND Month(T0.DocDate) <=9)
+ 
(select  SUM((T1.DocTotal-T1.Vatsum-T1.[TotalExpns])*-1) 
 FROM ORIN T1 
WHERE T1.CANCELED = 'N' and T1.DocDate between @fechainicio and @fechafin 
AND Month(T1.DocDate) <=9)
) as 'Septiembre',


((select SUM(T0.DocTotal-T0.Vatsum-T0.[TotalExpns])
FROM OINV T0 
WHERE T0.CANCELED = 'N' and T0.DocDate between @fechainicio and @fechafin
AND Month(T0.DocDate) <=10)
+ 
(select  SUM((T1.DocTotal-T1.Vatsum-T1.[TotalExpns])*-1) 
 FROM ORIN T1 
WHERE T1.CANCELED = 'N' and T1.DocDate between @fechainicio and @fechafin 
AND Month(T1.DocDate) <=10)
) as 'Octubre',

((select SUM(T0.DocTotal-T0.Vatsum-T0.[TotalExpns])
FROM OINV T0 
WHERE T0.CANCELED = 'N' and T0.DocDate between @fechainicio and @fechafin
AND Month(T0.DocDate) <=11)
+ 
(select  SUM((T1.DocTotal-T1.Vatsum-T1.[TotalExpns])*-1) 
 FROM ORIN T1 
WHERE T1.CANCELED = 'N' and T1.DocDate between @fechainicio and @fechafin 
AND Month(T1.DocDate) <=11)
) as 'Noviembre',

((select SUM(T0.DocTotal-T0.Vatsum-T0.[TotalExpns])
FROM OINV T0 
WHERE T0.CANCELED = 'N' and T0.DocDate between @fechainicio and @fechafin
AND Month(T0.DocDate) <=12)
+ 
(select  SUM((T1.DocTotal-T1.Vatsum-T1.[TotalExpns])*-1) 
 FROM ORIN T1 
WHERE T1.CANCELED = 'N' and T1.DocDate between @fechainicio and @fechafin 
AND Month(T1.DocDate) <=12)
) as 'Diciembre'
1 me gusta