Displaying different fields based on condition

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

Guest

Hi all

I have 2 tables with this structure

Table1
- fldID (pk
- fldDesign (fk
- fldPowe

Table2
- fldDesign (pk
- fldPowerF
- fldPowerT
- fldBuffer
- fldBuffer

What I'd like to do is
IF Table1.fldPower falls BETWEEN fldBufferFr AND fldBufferTo THEN fldBuffer1 will be used/display ELSE fldbuffer2 WHERE Table1.fldDesign = Table2=fldDesig

Is this possible to be done in the Query design? I'm using Access 200

TIA,
Djoez
 
Djoezz

This should work for you

The IIF statement is really nice.

SELECT IIF(Table1.fldPower BETWEEN fldBufferFr and fldBufferTo,fldBuffer1,fldBuffer2) FROM Table1 INNER JOIN Table2 ON Table1.fldDesign=Table2.fldDesig

From MSAccess Help

IIf Functio

Returns one of two parts, depending on the evaluation of an expression

Synta

IIf(expr, truepart, falsepart

The IIf function syntax has these named arguments

Part -Description
expr -Required. Expression you want to evaluate.
truepart -Required. Value or expression returned if expr is True.
falsepart -Required. Value or expression returned if expr is False.

Remark

IIf always evaluates both truepart and falsepart, even though it returns only one of them. Because of this, you should watch for undesirable side effects. For example, if evaluating falsepart results in a division by zero error, an error occurs even if expr is True

Hope this helps

Jim
 
Back
Top