How to zero out all negative numbers in a group-by T-SQL statement
You could use a CASE
statement
SUM(CASE WHEN i.Quantity < 0 THEN 0 ELSE i.Quantity END)
Or a more obscure version
SUM(NULLIF(i.Quantity, -ABS(i.Quantity)))
or just exclude these rows altogether in the WHERE
clause if they are not needed for any other purpose.
just filter out the ones you don't want...
WHERE quantity > 0