Just an aside:
When dividing through a constant value always add a decimal point and at
least one zero (--> 100.0 or 100.00 instead of 100).
If you do not specify a decimal point a numeric constant is interpreted as
integer and if you divide an integer through an integer, the result will be
always an integer value, i.e. decimal values are truncated:
--> 95/100 = 0!
Just execute the following SQL Statement and see the difference:
Values(95/100 * 500, 95/100.0 * 500);;
Mit freundlichen Grüßen / Best regards
Birgitta Hauser
"Shoot for the moon, even if you miss, you'll land among the stars." (Les
Brown)
"If you think education is expensive, try ignorance." (Derek Bok)
"What is worse than training your staff and losing them? Not training them
and keeping them!"
?Train people well enough so they can leave, treat them well enough so they
don't want to.? (Richard Branson)
-----Ursprüngliche Nachricht-----
Von: MIDRANGE-L [mailto:midrange-l-bounces@xxxxxxxxxxxx] Im Auftrag von Bob
Cagle
Gesendet: Wednesday, 02.11 2016 21:22
An: Midrange Systems Technical Discussion
Betreff: RE: Run SQL Scripts - '+++++' in results
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
--
This is the Midrange Systems Technical Discussion (MIDRANGE-L) mailing list
To post a message email: MIDRANGE-L@xxxxxxxxxxxx To subscribe, unsubscribe,
or change list options,
visit:
http://lists.midrange.com/mailman/listinfo/midrange-l
or email: MIDRANGE-L-request@xxxxxxxxxxxx Before posting, please take a
moment to review the archives at
http://archive.midrange.com/midrange-l.
Please contact support@xxxxxxxxxxxx for any subscription related questions.
As an Amazon Associate we earn from qualifying purchases.