English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

I want to perform some If/Then statements in Access. It would take the form of "if column A > col B, then subtract B from A and place the result in (present) col C, or simply return the result of zero (to col C). likewise, another problem would be if col A > than col B, then mult col A by col D and return the result to col E, otherwise, result to col E of zero. thanks.

2007-11-20 15:11:09 · 2 answers · asked by 27ysq 4 in Computers & Internet Programming & Design

no, i definitely mean Access, but i appreciate your response nonetheless.

2007-11-20 15:38:17 · update #1

2 answers

Try a query like the following:

SELECT Table1.columnA,
Table1.columnB,
IIf(Table1!columnA>Table1!columnB,Table1!columnA-Table1!columnB,0) AS columnC,
Table1.columnD,
IIf(Table1!columnA>Table1!columnB,Table1!columnA*Table1!columnD,0) AS columnE
FROM Table1;

2007-11-20 15:37:00 · answer #1 · answered by manbearpig_must_die 2 · 2 0

You say Access, but your example sounds like Excel. In Excel, you can't perform an operation on an entire column at a time but you can code an IF in C that does the calculation on the A and B cells on its row. Copying that formula to other cells in C will automatically adjust any row numbers by the number of rows down or up you copy it.

For example: IF( A3 > B3, A3-B3, 0 ) in C3, if copied to C4, would automatically be converted to IF( A4 > B4, A4-B4, 0 )

Hope that helps.

2007-11-20 23:23:06 · answer #2 · answered by The Phlebob 7 · 0 2

fedest.com, questions and answers