I have two tables (Items and Item_Types), and I want to do something like the following as a formula in a calculated column in the Item_Types table:
SELECT SUM(Items.Qty_In_Stock) FROM Items WHERE Items.Item_Type = Item_Types.ID
But Management Studio isn’t liking it.
How can I do this? Or have I just got my syntax wrong? I’m not great with SQL.
Thanks
EDIT: I think I need to be more specific.
One ItemType can have many Items.
Each Item has a Qty_In_Stock field.
I want to get a sum of all Qty_In_Stock fields where Items.Item_Type = Item_Types.ID – not just a sum of the entire column.
Cheers
Assuming you are trying to show the available qty for each item type:
I would recommend creating a view that shows this information:
You will need to “GROUP BY” the item type.
Once you have created the view, you can query it as if it were a table: