Rico Brouwer Rico Brouwer - 10 months ago 45
C# Question

Combine the results of a sql query together in one result

I have an application(C#) that manages a stock level for every storage unit.
But now i want a complete overview of the stock level of every product from every stock unit together.

For example i have

apples (ProductID 1) in unit one and
in unit two and I use this query:

select StockLevel
from Supply
where ProductID = '1'

And put the result in a textbox it will always gives me the first stocklevel of 50 apples and not 75.

Is there a way i can combine these results in an easy way?

Answer Source

If you want to combine, you want an aggregate function, sum in your case:

 select sum(StockLevel)
   from Supply
  where ProductID = '1' 

and get the apples being summed up: 75 which is 50 + 25