Sam, I had already added a cast to that CommRate calculation with no effect. That calculation just gets the human-readable version of the rate, i.e. 3.00 for 3%.
What finally solved it is in the cte_Comms where I calculate the actual commissions and have to further divide the rate to get the multiplier, I added an additional Cast around that calc:
cast(sum(cte_NetSales.NetSales * cast((cte_CommRate.CommRate/100) as dec(5,4))) as dec(32,16)) as Commission
That extra nested Cast is what did the trick. No more plus signs!
Thanks everyone for all of the suggestions.
Bob
-----Original Message-----
From: Sam_L
SQL jumps thru hoops, I believe, to retain precision when doing calculations. (It's all explained somewhere in the manual, but floating point can be involved.) So in
Select A5AN8 as Customer, (A5CMR1 + A5CMR2)/1000 as CommRate I have no idea what precision CommRate is, or what type is is.
I'd suggest something like
Select A5AN8 as Customer, cast((A5CMR1 + A5CMR2)/1000 as dec(9,2) as CommRate
Or maybe it should be 9.3, because you divide it by 100 further down.
You might also want to do something similar where you calculate Commission.
If the hex came out as blanks, then I'd guess (maybe) it was null. Not sure why--maybe a join results in a null because there is no match.
Can you isolate one customer and item where it occurs and hard code them in the first CTE to make debugging easier.
Sam
On 11/1/2016 2:31 PM, Bob Cagle wrote:
Sam
Thanks for the hex suggestion - unfortunately, that column is also showing all plus signs.
CommRate is already being cast to dec(9,2), and doing a cast on Commission to dec(10,2) has no effect either.
I'll keep trying things...
Thanks
Bob
As an Amazon Associate we earn from qualifying purchases.