SQL output: IF Access 2010

I am trying to write a query in Access 2010. I have a table:

power

The name of the table power. I am trying to write an IF statement:

Select IIf(power.gain_type = 'D', power.gain_max + 2.15)

If the gain_type value is D, then the gain_max value is 2.15

For instance:

14.8 + 2.15 = 16.95.

Thanks in advance!

+5
source share
3 answers

Now I am wondering how to insert ELSEIF status. "IF (gain_type = 'D') {gain_max + 2.15} ELSEIF (gain_type = 'I') {gain_max-2.15} ELSE {gain_max}

You can use SWITCH

Select power.gain_max + Switch(power.gain_type='D', 2.15,
                               power.gain_type='I', -2.15,
                               true, 0)
from power

or socket / chain IIFs

Select power.gain_max + IIf(power.gain_type='D', 2.15,
                        IIf(power.gain_type='I', -2.15, 0))
from power

Original

It makes a choice

Select IIf(power.gain_type='D', power.gain_max+2.15, power.gain_max)
from power

Are you trying to update?

update power
set gain_max = gain_max+2.15
where gain_type='D'

You can also use the fact that TRUE = -1 in Access

Select power.gain_max-2.15*(power.gain_type='D')
from power

References

+8

iif(condition, value_if_true, value_if_false). , :

IIf(power.gain_type='D', 
    power.gain_max+2.15,
    power.gain_max)
+1

Result: IIf ([gain_type] = "D", [gain_max] +2.15, [gain_max])

enter image description here

0
source

All Articles