If we have a table like this:
Grp Value
Grp1 2
Grp1 5
Grp1 3
Grp2 3
Grp2 -5
Grp2 -2
Grp3
This comes from CodePlex "Aggregate Product function extends SQL". I modified the statement to return the desired results except for the NULL group, it returns "1".
SELECT GrpID, Exp(Sum(IIf(Abs(ISNULL(value,1))=0,0,Log(Abs(ISNULL(value,1))))))*IIf(Min(Abs(ISNULL(value,1)))=0,0,1)*
(1-2*(Sum(IIf(ISNULL(value,1)>=0,0,1)) % 2)) AS value
FROM @foo
GROUP BY GrpID;
GrpID Value
Grp1 30
Grp2 30
Grp3 0
Grp4 8
Grp5 7
Grp6 1
Grp7 -10
ref: http://productfunctionsql.codeplex.com/