Hola Kenneth
Yo hice este, puede servirte de guía
--SET Arithabort OFF
--SET ANSI_WARNINGS OFF
/* SELECT FROM [dbo].[OINM] T1 */
DECLARE @dateInicio DATETIME
/* WHERE */
SET @dateInicio = '20150101'--/* T1.DocDate */ '[%0]'
/* SELECT FROM [dbo].[OINM] T1 */
DECLARE @dateFinal DATETIME
/* WHERE */
SET @dateFinal = '20150301'--/* T1.DocDate */ '[%1]'
/* SELECT FROM [dbo].[OITB] T2 */
DECLARE @grupodesde AS NVARCHAR(30)
/* WHERE */
SET @grupodesde = ''--/* T1.ItmsGrpNam */ '[%2]'
/* SELECT FROM [dbo].[OITB] T2 */
DECLARE @grupohasta AS NVARCHAR(30)
/* WHERE */
SET @grupohasta = ''--/* T1.ItmsGrpNam */ '[%3]'
/* SELECT FROM [dbo].[OITM] T0 */
DECLARE @productodesde AS NVARCHAR(30)
/* WHERE */
SET @productodesde = ''--/* T0.ItemCode */ '[%4]'
/* SELECT FROM [dbo].[OITM] T0 */
DECLARE @productohasta AS NVARCHAR(30)
/* WHERE */ SET @productohasta = ''--/* T0.ItemCode */ '[%5]'
select t0.articulo [Artículo], t0.ItemName [Descripción], t3.Consumo*t1.Price 'Consumo',
((t3.saldoinic-t3.salidas)* t1.Price) 'Stock Inicial $',
cast(ISNULL(X2.Compras,0)as decimal(16,2))'Compras',
cast(ISNULL(X3.Ventas,0) as decimal(16,2)) 'Ventas',
(t1.SaldoFin * t1.Price) 'Stock Final $',
cast(ISNULL(X3.CostoVenta,0) as decimal (16,2)) 'Costo Venta' ,
cast(ISNULL((X3.Ventas-X3.CostoVenta),0)as decimal (16,2))'Ganancia',
convert(decimal (16,2),case isNull(X3.Ventas,0)
when 0 then 0 else ((IsNull(X3.Ventas,0)-IsNull(X3.CostoVenta,0))/IsNull(X3.Ventas,0) *100) end)'%',
round(convert(decimal (16,2),case ((IsNull(t3.saldoInic,0) +IsNull(t3.saldoInic,0) +IsNull(t1.SaldoFin,0)) /2)
when 0 then 0 else (IsNull(t3.Consumo,0)) / nullif(((IsNull(t3.saldoInic,0) +
IsNull(t3.saldoInic,0) +IsNull(t1.SaldoFin,0)) /2),0) end),-1)'Rotación Veces',
--(365)/
case when
(
round(convert(decimal (16,2),case ((IsNull(t3.saldoInic,0) +IsNull(t3.saldoInic,0) +IsNull(t1.SaldoFin,0)) /2)
when 0 then 0 else (IsNull(t3.Consumo,0)) /
((IsNull(t3.saldoInic,0) +IsNull(t3.saldoInic,0) + IsNull(t1.SaldoFin,0)) /2) end),-1)) = 0 then 0
else
(365)/
(round(convert(decimal (16,2),case ((IsNull(t3.saldoInic,0) +IsNull(t3.saldoInic,0) +IsNull(t1.SaldoFin,0)) /2)
when 0 then 0 else (IsNull(t3.Consumo,0))/
((IsNull(t3.saldoInic,0) +IsNull(t3.saldoInic,0) + IsNull(t1.SaldoFin,0)) /2) end),-1)) end
'Rotación Días',
(CASE WHEN EntMas = 0 THEN (EntMas*t1.Price)
WHEN EntMas > 0 AND EntMas < = SaltoT THEN 0
WHEN SaltoT > 0 AND EntMas > = SaltoT THEN (EntMas - SaltoT)*T1.Price
WHEN SaltoT = 0 AND EntMas &