on 2010 May 20 11:38 PM
Necesito hacer una consulta donde quiero sacar el costo promedio del articulo en total(osea por todas las bodegas)
hasta ahora llevo la consulta asi:
SELECT T0.[ItemCode] as 'CODIGO', T0.[ItemName] AS 'ARTICULO', T0.[OnHand] AS 'STOCK POR BODEGA', T0.[IsCommited] AS 'COMPROMETIDO POR BODEGA', (T0.[OnHand]-T0.[IsCommited]) as 'DISPONIBLE POR BODEGA', T0.[LstEvlPric] AS 'ULTIMO PRECIO DETERMINADO',T0.[LastPurPrc] AS 'ULTIMO PRECIO DE COMPRA', T0.[MaxLevel] AS 'MAXIMO', T0.[MinLevel] AS 'MINIMO', T1.[OnHand] AS 'STOCK', T1.[IsCommited] AS 'COMPROMETIDO',(T1.[OnHand]-T1.[IsCommited]) AS 'DISPONIBLE' ,T1.[AvgPrice] AS 'COSTO PROMEDIO', T2.[WhsCode] AS 'CODIGO', T2.[WhsName] AS 'ALMACEN',FROM OITM T0 INNER JOIN OITW T1 ON T0.ItemCode = T1.ItemCode INNER JOIN OWHS T2 ON T1.WhsCode = T2.WhsCode
me falta sacar el promedio porque el que me saca el sistema es costo promedio por bodega y en nuestra empresa manejamos varias bodegas y nos interesa sacar el costo promedio pero en general, por todas las bodegas.
Agradezco que me ayuden con esta consulta
gracias
Hola.
Para el cálculo del costo promedio se me ocurre hacerlo promediando el costo promedio de todos los almacenes.
La consulta quedaría algo así:
SELECT T0.ItemCode as 'CODIGO', T0.ItemName AS 'ARTICULO', T0.OnHand AS 'STOCK',
T0.IsCommited AS 'COMPROMETIDO', (T0.OnHand-T0.IsCommited) as 'DISPONIBLE',
T0.LstEvlPric AS 'ULTIMO PRECIO DETERMINADO',T0.LastPurPrc AS 'ULTIMO PRECIO DE COMPRA', T0.AvgPrice,
T0.MaxLevel AS 'MAXIMO', T0.MinLevel AS 'MINIMO', T1.OnHand AS 'STOCK alm', T1.IsCommited AS 'COMP ALM',
(T1.OnHand-T1.IsCommited) AS 'DISPON ALM' ,T1.AvgPrice AS 'COSTO PROMEDIO', T2.WhsCode AS 'COD.ALM',
T2.WhsName AS 'ALMACEN',
'Costo Prom Tot'=(SELECT SUM(T10.AvgPrice)/COUNT(T10.WhsCode) AS CP FROM OITW T10 WHERE
T10.ItemCode = T0.ItemCode AND T10.AvgPrice > 0)
FROM OITM T0
INNER JOIN OITW T1 ON T0.ItemCode = T1.ItemCode
INNER JOIN OWHS T2 ON T1.WhsCode = T2.WhsCode
Afregué el campo "T0.AvgPrice" que trae el costo promedio que figura en el maestro del artículo, para que lo compares contra lo calculado en "Costo Prom Tot".
Pruébala, analízala y nos cuentas si la consulta cumple con el requerimiento.
Saludos.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Muchas gracias por tu ayuda ya pude solucionar.
Edited by: jcarito on May 21, 2010 2:55 PM
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
91 | |
9 | |
8 | |
6 | |
5 | |
5 | |
4 | |
4 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.