Reputation: 89
I have two Tables in my Database. The first table has columns Serial,Date,Location, Type,Condition,Color,Loaned_To, ProductNumberREF, and Department.
The next table has Product Number,Type,Brand,and Price.
With this system i am able to alter the Price of all items in the Main table without going one by one. But now i am running into a problem.
I'm creating a Total money spend Label that i want to populate with all the sums of prices of all the items in a Gridview. How do i add the Sum of all prices in a table that doesn't contain prices but has to reference to another table?
SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnString"].ConnectionString);
conn.Open();
SqlCommand SpentCheck = new SqlCommand("Selct Sum(Price) From Items");
this Code was my initial attempt till i realized PRICE doesn't exist in ITEMS. So how do i get the sum of all Prices in ITEMS?
UPDATE#####
I tries the first answers Suggestions this is were i am now
Upvotes: 0
Views: 63
Reputation: 19743
You are looking for an SQL join.
SELECT
SUM(Price)
FROM
Items
INNER JOIN ProductNumber ON Items.Product_NumberREF = ProductNumber.ProductNumber
Upvotes: 2