Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Sql query Average balance

Posted on 2008-10-06
7
Medium Priority
?
253 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
  • 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

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 2000 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

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

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

I've encountered valid database schemas that do not have a primary key.  For example, I use LogParser from Microsoft to push IIS logs into a SQL database table for processing and analysis.  However, occasionally due to user error or a scheduled task…
Introduction: When running hybrid database environments, you often need to query some data from a remote db of any type, while being connected to your MS SQL Server database. Problems start when you try to combine that with some "user input" pass…
Integration Management Part 2
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…

916 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