If positive, sum all items. If negative, return each one
Try this:

SELECT   salesid, sum(num) as num
FROM     #BE
WHERE    num &gt; 0
GROUP BY salesid
UNION ALL
SELECT   salesid, num
FROM     #BE
WHERE    num &lt; 0;


If you want both the sum values in one row then you must create a maxValue (and minValue) function and use this as sum(maxValue(0, num)) and sum(minValue(0, num)). This is described in: Is there a Max function in SQL Server that takes two values like Math.Max in .NET?