[英]SQL: IF statement Access 2010
I have trying to write a query in Access 2010. I have a table: 我试图在Access 2010中编写一个查询。我有一个表:
Table name is power
. 表名是
power
。 I have trying to write IF statement: 我试着写IF语句:
Select IIf(power.gain_type = 'D', power.gain_max + 2.15)
If gain_type equals D, then gain_max sum 2.15
如果gain_type等于D,则gain_max总和为2.15
For example: 例如:
14.8 + 2.15 = 16.95.
14.8 + 2.15 = 16.95。
Thanks in advance! 提前致谢!
Now I wondering how to insert an ELSEIF statment.
现在我想知道如何插入ELSEIF语句。 "IF (gain_type='D'){gain_max+2.15} ELSEIF (gain_type='I'){gain_max-2.15} ELSE {gain_max}
“IF(gain_type ='D'){gain_max + 2.15} ELSEIF(gain_type ='I'){gain_max-2.15} ELSE {gain_max}
You can either use SWITCH 您可以使用SWITCH
Select power.gain_max + Switch(power.gain_type='D', 2.15,
power.gain_type='I', -2.15,
true, 0)
from power
or nest/chain the IIFs 或嵌套/链接IIF
Select power.gain_max + IIf(power.gain_type='D', 2.15,
IIf(power.gain_type='I', -2.15, 0))
from power
This does the select 这就是选择
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 您还可以在Access中使用TRUE = -1的事实
Select power.gain_max-2.15*(power.gain_type='D')
from power
References 参考
The syntax is iif(condition, value_if_true, value_if_false)
. 语法是
iif(condition, value_if_true, value_if_false)
。 If you add a third parameter you should be fine: 如果你添加第三个参数你应该没问题:
IIf(power.gain_type='D',
power.gain_max+2.15,
power.gain_max)
Result: IIf([gain_type]="D",[gain_max]+2.15,[gain_max]) 结果:IIf([gain_type] =“D”,[gain_max] +2.15,[gain_max])
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.