¡Caminando hacia el éxito!

Aprende en Comunidad

Avalados por :

Cómo formar una consulta SELECT para restar dos columnas en SAP

  • Creado 01/03/2024
  • Modificado 01/03/2024
  • 45 Vistas
0
Cargando...

inv-table.png hi ,

I have two Tables,

1) Inventory table INV_TABLE : Having fields: material_no, quantity, user_id and location_no

2) Delivery Note Table DNOTE_TABLE: Having fields: DNOTE_NO, material_no, quantity, user_id, and many more.

Now we have a requirement, that we have to generate a stock report that has

Material_No, User_ID, Total_Available_Qty.

Here Total Available quantity is calculated by subtracting the Stock Table Quantity with Delivery Note table quantity

Can you assist in forming the select query...

I used Left Join but I am not getting proper count as well as negative values are populated in total_available_Qty. My Query is as follows

SELECT  DISTINCT INV.material_no,INV.USER_ID, (SUM(INV.quantity) - SUM(PICK.quantity)) AS TOT_QTY  
FROM INV_TABLE  INV LEFT JOIN 
DNOTE_TABLE  PICK ON INV.USER_ID = PICK.USER_ID AND INV.material_no = PICK.material_no 
WHERE  INV.quantity NOT IN ('0') 
GROUP BY INV.material_no, INV.USER_ID ORDER BY TOT_QTY 

That is, basically here as shown in the image, all the inventory table records should be fetched leaving the delivery note table records.

Kindly assist.

Regards

Govardan

inv-table.png
Pedro Pascal
Se unió el 07/03/2018
Pinterest
Telegram
Linkedin
Whatsapp

2 Respuestas

0
Cargando...

Hi,

Thanks a lot for the query above, but I still found some discrepancies. I am encountering some negative values. I have attached an image of the consolidated stock report that I actually need. Could you please help me fine-tune the query?

consolidated-stock-report.png
Respondido el 15/04/2024
LUCIANO RIOJA GHIOTTO
Se unió el 13/07/2019
0
Cargando...

HOLA

Prueba esto

SELECT material, usuario, sum ( facturado - recogido ) COMO "TOTAL"
DE  
( SELECT INV.material_no como "material", 
       INV.USER_ID como "usuario" ,
       INV.quantity como "facturado" 
       PICK.quantity como "recogido"
DE INV_TABLE  como INV LEFT JOIN DNOTE_TABLE  como PICK EN INV.USER_ID = PICK.USER_ID Y INV.material_no = PICK.material_no 
DONDE  INV.quantity > 0 ) como "final"


AGRUPAR POR material, usuario
Respondido el 15/04/2024
LUCIANO RIOJA GHIOTTO
Se unió el 13/07/2019

contacto@primeinstitute.com

(+51) 1641 9379
(+57) 1489 6964

© 2024 Copyright. Todos los derechos reservados.

Desarrollado por Prime Institute

¡Hola! Soy Diana, asesora académica de Prime Institute, indícame en que curso estas interesado, saludos!
Hola ¿Puedo ayudarte?