how to add multiple colums in a querie?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have tried to add multiple colums in a but when i set the expression, it
just adds the numbers in each colum. Example: Colum a (2) + Colum b (4).
instead of it add 2+4 which = 6 it shows it as 24. What am i doing wrong?
 
Try wrapping the column's values in the CInt() function:
CInt([ColumnA]) + CInt([ColumnB])

If you're not dealing with integers, you can also use CSng() for singles,
CDbl() for doubles, etc.

Barry
 
Thanks this helps a lot. Can i add more than 2 colums? also does there need
to be a value in the colum fo rthe querie to work example: CInt([ColumnA]) +
CInt([ColumnB]) + CInt([ColumnC]) + CInt([ColumnD])

Barry Gilbert said:
Try wrapping the column's values in the CInt() function:
CInt([ColumnA]) + CInt([ColumnB])

If you're not dealing with integers, you can also use CSng() for singles,
CDbl() for doubles, etc.

Barry

Jafranklin2 said:
I have tried to add multiple colums in a but when i set the expression, it
just adds the numbers in each colum. Example: Colum a (2) + Colum b (4).
instead of it add 2+4 which = 6 it shows it as 24. What am i doing wrong?
 
You can add as many as you like. If there is a chance that column will have
no value (null), you need to add another function called Nz:

CInt(Nz([ColumnA]))+CInt(Nz([ColumnB]))

Nz returns zero if the value is null.

Also, if there's any risk that the column value will be non-numeric, this
will fail.

Barry

Jafranklin2 said:
Thanks this helps a lot. Can i add more than 2 colums? also does there need
to be a value in the colum fo rthe querie to work example: CInt([ColumnA]) +
CInt([ColumnB]) + CInt([ColumnC]) + CInt([ColumnD])

Barry Gilbert said:
Try wrapping the column's values in the CInt() function:
CInt([ColumnA]) + CInt([ColumnB])

If you're not dealing with integers, you can also use CSng() for singles,
CDbl() for doubles, etc.

Barry

Jafranklin2 said:
I have tried to add multiple colums in a but when i set the expression, it
just adds the numbers in each colum. Example: Colum a (2) + Colum b (4).
instead of it add 2+4 which = 6 it shows it as 24. What am i doing wrong?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top