I am trying to divide 2 funcitons by each other and I am coming back with 0 as my result in one of them while I am getting the correct answer in another. The two columns I am trying to pull with functions are:
SELECT
sum(D.PrincipalBal)/sum(L.PrincipalBal)*100 as DelqRatioByBal
, count(D.LoanID)/count(L.LoanID)*100 as DelqRatioByCnt
FROM Loan L
INNER JOIN DelqINFO D on D.LoanID = L.LoanID
I get the correct result back for 'DelqRatioByBal' but I get 0 back for 'DelqRatioByCnt'
Any suggestons?
that because you are doing an integer division
take a look at this
select 1/2 --int division
select (1.00*1)/2
go
--
SELECT
sum(D.PrincipalBal)/sum(L.PrincipalBal)*100 as DelqRatioByBal
, (1.00*count(D.LoanID))/count(L.LoanID)*100 as DelqRatioByCnt
--
any number multiplied by 1 = the number
|||Thanks Joey, worked well. I appreciate it.
No comments:
Post a Comment