I am new to learning SQL and am trying to figure out how to so some summing on a field within a query.
I have a table that holds the Quantity On Hand (QOH) for each inventory item in all 4 stores. If I run a query for one specific inventory item the results look like this:
Store InventoryID QOH
1 196196 0
2 196196 2
3 196196 -1
4 196196 0
I need to be able to sum the QOH and be able to use that number in the where clause. Here's the catch though...If the value of the QOH is <= 0 then I want the value set to 0. I don't want any negative numbers. In the above data if I do a sum the total comes out to be 1 rather than 2 (which I know 1 is mathmatically correct). So my question is how do I parse though the QOH on each store and set the negatives = 0 and then sum the amount for the QOH for each InventoryID.
Any suggestions on how to do this would be great.