Quantcast
Channel: SCN: Message List
Viewing all articles
Browse latest Browse all 8526

Re: Query Normas de reparto

$
0
0

Te dejo un Query tal vez te ilumina un poco el camino

 

 

Select   T0.ItemCode                  

        ,T0.ItemName

        ,T0.SalUnitMsr'Unidad Medida'             

        ,sum(T0.Saldo_Inicial)  'Saldo_Inicial'

        ,sum(T0.Entradas)       'Entradas'

        ,sum(T0.Salidas)        'Salidas'

        ,sum(T0.Saldo_Final)    'Saldo_Final'

        ,sum(T0.CostoTotal)     'Costo_Total'

        ,'Costo_Unitario' =      CASE

                                 WHEN sum(T0.Saldo_Final) = 0

                                 THEN 0  ELSE sum(T0.CostoTotal) / sum(T0.Saldo_Final)

                                 END

from (  SELECT                  T1.[ItemCode]

                               ,T1.[ItemName]

                               ,T1.[SalUnitMsr]

                               ,sum((T0.[InQty]- T0.[OutQty])) 'Saldo_Inicial'

                               ,0 'Entradas'

                               ,0 'Salidas'

                               ,sum((T0.[InQty]- T0.[OutQty])) 'Saldo_Final'

                               ,sum(T0.[TransValue]) 'CostoTotal'

                               ,0 'CostoUnitario'

        FROM [dbo].[OINM] T0  INNER JOIN [dbo].[OITM] T1 ON T0.ItemCode = T1.ItemCode

        WHERE T0.[DocDate] < '[%0]'

        GROUP BY T1.[ItemCode], T1.[ItemName],T1.[SalUnitMsr]

        UNION ALL

        SELECT                 T1.[ItemCode] 'Codigo'

                               ,T1.[ItemName]              'Descripcion'

                               ,T1.[SalUnitMsr] 'Unidad Medida'

                               ,0                            'Saldo_Inicial'

                               ,sum(T0.[InQty]) 'Entradas'

                               ,sum(T0.[OutQty])'Salidas'

                               ,sum((T0.[InQty]- T0.[OutQty])) 'Saldo_Final'

                               ,sum(T0.[TransValue]) 'CostoTotal'

                               , 0

        FROM [dbo].[OINM] T0  INNER JOIN [dbo].[OITM] T1 ON T0.ItemCode = T1.ItemCode

        WHERE T0.[DocDate] >= '[%0]' AND T0.[DocDate] <= '[%1]'

        GROUP BY T1.[ItemCode], T1.[ItemName],T1.[SalUnitMsr]

      ) [T0]

GROUP BY T0.[ItemCode], T0.[ItemName], T0.SalUnitMsr


Viewing all articles
Browse latest Browse all 8526

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>