This is related to a question I asked in the forum before and it looks like it is not handling the negative numbers within the log expression. Please let me know.
declare @insurance table
;with cte as
select groupid,classid,creditamt,debitamt,ROW_NUMBER() over (partition by GroupId order by ClassId ) as rn from @insurance
select t.GroupId,t.debitamt,t1.Amt from
(select * from cte where rn = 1)t
inner join (select GroupId,exp(SUM(LOG(CAST(isnull(creditamt,debitamt) as decimal(8,4))) )) as Amt from cte where rn <> 1 group by GroupID)t1 on t.GroupID = t1.GroupID
select * from cte1 -- this bombs when the inside log expression is NEGATIVE or ZERO.
View Complete Post