Q: SQL SUM() function always returns 0 I'm executing this statement on an ASP.NET platform with SQL Server 
SELECT id, size, color, 
        SUM(CASE WHEN storeID IN ('E13','E15','E10') THEN stock ELSE 0 END) 
        + SUM(CASE WHEN storeID IN ('E13','E15','E10') THEN incoming ELSE 0 END) 
        - SUM(CASE WHEN storeID IN ('E13','E15','E10') THEN outgoing ELSE 0 END) 
    AS Total 
FROM stocks 
GROUP BY id, size, color

And this is the code I'm using to retrieve the obtained values
For Each rowStock In TableStocks.Rows
    Dim product As New ProductInfo
    With product
        .id = rowStock("id")
        .size = rowStock("size")
        .color = rowStock("color")
        .stock = rowStock("Total")
    End With
Next

id, size and color values are correct, but the result of the SUM function is always 0. If I run the query on the SQL Server management it works fine.
I've tried changing
.stock = rowStock(3)

instead of 
.stock = rowStock("Total")

but I'm getting the same result. I can't figure what I'm missing.

A: Finally I found a solution to my own question. I've saved my query into a stored procedure on the database and it works as I expected.
EDIT
I've found another solution without using stored procedures. I realized that before running the sql statement, it's converted to lower case. So I decided to use COLLATE SQL_Latin1_General_CP1_CI_AS in storeID field, just to give it a try. It worked!
The final SQL query is
SELECT id, size, color,  
    SUM(CASE WHEN storeID COLLATE SQL_Latin1_General_CP1_CI_AS 
    IN ('E13','E15','E10') THEN stock + incoming - outgoing ELSE 0 END)  
  AS Total 
FROM stocks 
GROUP BY id, size, color


A: The only thing I see is the extra comma after "total," which indicates another column name is expected in the query before the "from" keyword and choking...
Other than that, I would alter your query to ...
SELECT
      id, size, color, sum( stock + incoming - outgoing ) as Total
   FROM
     stocks 
   where
      storeID IN ('E13','E15','E10')
   GROUP BY 
      id, size, color

