Solved

Sql query Average balance

Posted on 2008-10-06
7
244 Views
Last Modified: 2012-05-05
I am trying to get an avearge balance within my sql select stmt and getting back a different number, i do this on a calculator and a number match

based on this logic
Finance charge divide it by the APR divided by 12 i should get average balance of 14,862.09

Finance charge=184.29
Apr = 14.88

my select stmt
cast(case when e.interestrate = 0 then 0 else abs(l.fin_chrg/(e.interestrate/12)) end as decimal(6,2)) as AAVGBALA,

gives me 148.62, but i should be getting 14,862.09


e.interestrate  = apr
l.fin_chrg - finance charge

0
Comment
Question by:fahVB
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
  • 2
  • +1
7 Comments
 
LVL 60

Expert Comment

by:chapmandew
ID: 22653702
are you dividing by 100 anywhere?  I can't see that you are, but I can't look at  your values either...
0
 
LVL 1

Expert Comment

by:Chris Brock
ID: 22653705
It looks like it's getting confused with the percentage... try this and see how it looks:

cast(case when e.interestrate = 0 then 0 else abs(l.fin_chrg/(e.interestrate/12))*100 end as decimal(6,2)) as AAVGBALA,
0
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 22653713
I guess you are missing a multiplication factor of 100?!
0
Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

 

Author Comment

by:fahVB
ID: 22653751
yes, when *100 i get following error

Msg 8115, Level 16, State 6, Line 10
Arithmetic overflow error converting float to data type numeric.

(0 row(s) affected)


0
 
LVL 1

Expert Comment

by:Chris Brock
ID: 22653770
Is your data type set to percentage? That would cause it to divide by 100.
0
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 500 total points
ID: 22653837
you will need to use
cast(case when e.interestrate = 0 then 0 else abs(l.fin_chrg/(e.interestrate/12)) end as decimal(16,2)) as AAVGBALA,

instead. because otherwise decimal(6,2) will only allow numbers up to 9999.99
0
 

Author Closing Comment

by:fahVB
ID: 31503582
darn me, you guys are good. It worked
0

Featured Post

[Webinar] How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you having speed problem in loading SQL Server Management Studio, try to uncheck these options in your internet browser (IE -> Internet Options / Advanced / Security):    . Check for publisher's certificate revocation    . Check for server ce…
In SQL Server, when rows are selected from a table, does it retrieve data in the order in which it is inserted?  Many believe this is the case. Let us try to examine for ourselves with an example. To get started, use the following script, wh…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

632 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question