Question

J'ai essayer d'écrire une requête dans Access 2010. J'ai une table:

puissance

Nom de la table est power. Je tente d'écrire instruction IF:

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

Si gain_type est égal à D, puis somme gain_max 2,15

Par exemple:

14,8 + 2,15 = 16,95.

Merci à l'avance!

Était-ce utile?

La solution

Maintenant, je me demandais comment insérer un statment ELSEIF. « IF (gain_type = 'D') {gain_max + 2,15} ELSEIF (gain_type = 'I') {gain_max-2,15} else {} gain_max

Vous pouvez utiliser SWITCH

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

ou nid / chaîne les CII

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

Original

fait la sélection

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

Vous essayez de mise à jour?

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

Vous pouvez aussi utiliser le fait que TRUE = -1 dans Access

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

Références

Autres conseils

La syntaxe est iif(condition, value_if_true, value_if_false). Si vous ajoutez un troisième paramètre que vous devriez être bien:

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

Résultat: IIf ([gain_type] = "D", [gain_max] 2,15 [gain_max])

entrer image description ici

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top