select case when ((a is not null) and (b is not null)) then b else a end from tablename
select case when a is not null and b is not null then b else a end from tb
select case when (a is not null and b is not null) then b else a end from tb
iif函数iif(a is not null and b is not null ,b,a)select case when a is not null and b is not null then b else a end from tb
select case when A is null or B is null then A else B end from tb
LZ是用ACcess。 所以必须用access的函数。 iif, switch select iif(a is not null and b is not null ,b,a)select switch(a is not null and b is not null,b,a is null or b is not null,a)1.IIf 函数
select iif(col='0','ok',iif(col='1','err1',iif(col='2','err2','err3'))) as colname from table
2. Switch 在Access无法使用SQL语句中的case when语句,但可以通过Switch函数实现 例如: Switch(成绩<60,"不及格",成绩 Between 61 And 74,"中",成绩 Between 75 And 88,"良",成绩 Between 88 And 100,"优") AS 成绩等级 可以实现对成绩的值进行多分支条件判断结构
select case when (a is not null and b is not null) then b else a end from tb
select case when (a is not null and b is not null) then b else a end from tb
select case when A is null or B is null then A else B end from tb
所以必须用access的函数。
iif,
switch
select iif(a is not null and b is not null ,b,a)select switch(a is not null and b is not null,b,a is null or b is not null,a)1.IIf 函数
根据表达式的值,来返回两部分中的其中一个。
语法 IIf(expr, truepart, falsepart)
IIf 函数的语法含有下面这些命名参数:
部分 描述
expr 必要参数。用来判断真伪的表达式。
truepart 必要参数。如果 expr 为 True,则返回这部分的值或表达式。
falsepart 必要参数。如果 expr 为 False,则返回这部分的值或表达式。
说明
由于 IIf 会计算 truepart 和 falsepart,虽然它只返回其中的一个。因此要注意到这个副作用。例如,如果 falsepart 产生一个被零除错误,那么程序就会发生错误,即使 expr 为 True。
select iif(col='0','ok',iif(col='1','err1',iif(col='2','err2','err3'))) as colname
from table
2. Switch
在Access无法使用SQL语句中的case when语句,但可以通过Switch函数实现
例如:
Switch(成绩<60,"不及格",成绩 Between 61 And 74,"中",成绩 Between 75 And 88,"良",成绩 Between 88 And 100,"优") AS 成绩等级
可以实现对成绩的值进行多分支条件判断结构