Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SQL Sum

Status
Not open for further replies.

gary1975

Programmer
Oct 12, 2004
8
GB
Hi

I am trying to add a few coloums, but I continually get the answer of zero. I think it is happening because all the coloums I am using are integers. This is my formula which is part of a sql statement:

((Sum(york1.T20C156) + Sum(york1.T20C157)) / (Sum(york1.T20C155)))*100 AS varOwnerOcc

This is how would look with the numbers:

((38 + 30) / (83))*100 AS varOwnerOcc

Thanks

Gary
 
I would guess that as the values being divided are integers you are getting the rounded value.
Try converting them to decimals first and then execute

i.e.
Code:
SELECT ((convert(decimal(19,4),38) + convert(decimal(19,4),30)) / convert(decimal(19,4),83))* convert(decimal(19,4),100)

"I'm living so far beyond my income that we may almost be said to be living apart
 
sorry your statement should be :
Code:
SELECT ((Sum(convert(decimal(19,4),york1.T20C156)) + Sum(convert(decimal(19,4),york1.T20C157))) / (Sum(convert(decimal(19,4),york1.T20C155))))*100.00 AS varOwnerOcc


"I'm living so far beyond my income that we may almost be said to be living apart
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top