Calculation Column

aftabn10

Registered User.
Local time
Today, 07:32
Joined
Nov 4, 2008
Messages
96
I have two columns of numbers within my access db like the following:

80 | 8
27 | 4
14 | 0
4 | 0
210 | 0

What i would like to do is write a query that would divide the first column by the 2nd and give me a figures in %.

Is this possible within Access?

Please could somebody help. Thanks in advance.
 
The problem I see right off the bat is when Column2 is zero. You cant divide a number by 0. Now, if you didn't have a divisble by 0 error on rows where Column2 was zero, the sql would look like this:

Code:
SELECT [col1]/[col2] AS Calculation
FROM Table1;

Not sure what exact percentage you are looking to get though...
 
You can however do:

Code:
SELECT IIf([col2]=0,0,[col1]/[col2]) AS Calculation
FROM Table1;
 
Thanks Scooter and Bob, i will give that a go and let you know how i get on.
 
Thanks boblarson, that works perfectly. Thanks for your help as well Scooter. Just out of curiosity and for my knowledge what does IIf stand for?
 
IIF = Immediate IF, it is an IF you use in SQL instead of VBA

IIF ( Expresion, When True, When False) also look it up in the access help
 

Users who are viewing this thread

Back
Top Bottom