SQL Sum

1. Junior Member
Join Date
Dec 1969
Posts
4

## SQL Sum

Hi<BR><BR>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:<BR><BR>((Sum(york1.T20C156) + Sum(york1.T20C157)) / (Sum(york1.T20C155)))*100 AS varOwnerOcc<BR><BR>This is how it looks with numbers:<BR><BR>((38 + 30) / (83))*100 AS varOwnerOcc<BR><BR>Thanks<BR><BR>Gary

2. Senior Member
Join Date
Dec 1969
Posts
5,955

## What happens if you...

...you put each Sum() on its own into your SELECT statement? Do they contain the relevant values (i.e. 38, 30 and 83)?<BR><BR>SELECT ..., Sum(york1.T20C156), Sum(york1.T20C157), Sum(york1.T20C155) ...<BR><BR>Oliver.

3. Junior Member
Join Date
Dec 1969
Posts
4

## RE: What happens if you...

Ye it is part of a SELECT statement. I done reponse.writes for the values and they appear okay...<BR><BR>Thanks<BR><BR>Gary

4. Senior Member
Join Date
Dec 1969
Posts
5,955

## Right, then maybe you need...

...to specifically convert the integers to floats. Which DB are you using? I Access you can probably use CDbl(), but I would have thought that Access automatically spews out floats when you divide one integer by another.<BR><BR>Oliver.

5. Junior Member
Join Date
Dec 1969
Posts
4

## RE: Right, then maybe you need...

SQL Server

6. Senior Member
Join Date
Dec 1969
Posts
5,955

## Don't know SQL Server. Anybody else? <nb

.

7. Junior Member
Join Date
Dec 1969
Posts
4

## Got it! Thanks....

((Sum(convert(decimal(19,4),york1.T20C156)) + Sum(convert(decimal(19,4),york1.T20C157))) / (Sum(convert(decimal(19,4),york1.T20C155))))*100.0 0 AS varOwnerOcc

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•