Skip to main content
Answer

Summarize query table

  • November 25, 2024
  • 4 replies
  • 36 views

estebanperalta54
Captain II
Forum|alt.badge.img+4

Hi! I have this starting table which is called usrInventoryItem which shows inventory levels in my warehouse and bin locations:

I want to end up with the following view which essentially shows what is on hand (any warehouse locations not equal to Hold) and what is on hold (any warehouse locations equal to Hold):

 

 

How can I create this view in SQL?

Best answer by stoner7matt

Ok, not sure how you are connected to the database in sql, but here’s how i would write this in generic sql.

How are you connected to the database to use SQL? I would love to use that instead of Generic Inquiries

SELECT 
stats.InventoryID AS ItemID,
ii.InventoryCD AS ItemName,
ii.Descr AS ItemDescription,
SUM(stats.QtyOnHand) AS TotalQuantityOnHand,
SUM(stats.TotalCost) AS TotalInventoryCost
FROM
usrInventoryItem stats
JOIN
InventoryItem ii
ON
stats.InventoryID = ii.InventoryID
GROUP BY
stats.InventoryID, ii.InventoryCD, ii.Descr
ORDER BY
ii.InventoryCD;

 

4 replies

Forum|alt.badge.img
  • Jr Varsity II
  • November 25, 2024

Do you need to create this view in SQL or a Generic Inquiry?

 


estebanperalta54
Captain II
Forum|alt.badge.img+4

@stoner7matt I’m looking to create this in SQL


Forum|alt.badge.img
  • Jr Varsity II
  • Answer
  • November 25, 2024

Ok, not sure how you are connected to the database in sql, but here’s how i would write this in generic sql.

How are you connected to the database to use SQL? I would love to use that instead of Generic Inquiries

SELECT 
stats.InventoryID AS ItemID,
ii.InventoryCD AS ItemName,
ii.Descr AS ItemDescription,
SUM(stats.QtyOnHand) AS TotalQuantityOnHand,
SUM(stats.TotalCost) AS TotalInventoryCost
FROM
usrInventoryItem stats
JOIN
InventoryItem ii
ON
stats.InventoryID = ii.InventoryID
GROUP BY
stats.InventoryID, ii.InventoryCD, ii.Descr
ORDER BY
ii.InventoryCD;

 


Forum|alt.badge.img
  • Jr Varsity II
  • November 25, 2024

You can get this info from the INLocationStatus table or the INItemStats table from my understanding