You are doing the numeric logic after the sum()
. You need to do it inside the sum()
:
select e.[ ACCOUNT_NUM] as acct_num, 'MTL' as src
sum(case when isnumeric([ TRANSACTION_AMT]) = 1 then ABS([ TRANSACTION_AMT])
else 0
end) as abs_total_txn_amt
from mtb..MTEL e (nolock)
group by e.[ ACCOUNT_NUM];
And, you probably don't want e.[ TRANSACTION_AMT]
in the group by
.
I also simplified the logic so you are only adding up valid numeric values. It treats everything else as 0
.