New column

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

Guest

I have a created a table in access to consists of two columns both containing
numeric values. I would like to setup a query that when run creates a third
column which contains a value based on the addition of the two previous
columns. However this addition should only occur when the first column
contains a spefic value, therefore I would also like to use somekind of IF
statement to enable this.

Cheers

Nick
 
Dear Nick:

As a general rule, you should not store any derivable value in a table. If
you write a query that can derive the desired value, you can reference that
query just as you would access the table that has stored the value.

SELECT ColumnA, ColumnB,
IIf(ColumnA = 7, ColumnA + ColumnB, NULL) AS CSum
FROM YourTable

Change the names ColumnA, ColumnB, and YourTable above to the actual names
of these columns. Change CSum to whatever you want to call the derived
column. Change 7 to whatever value you want to test for in ColumnA in which
case you want the sum to be in the new column. Change NULL to be whatever
else you want in the summed column when ColumnA is not 7 (or whatever you
want to test).

Tom Ellison
 
Back
Top