如何在查询中插入if / else?
这是我的sqlcommand查询:
sqlcommand ("select Machine_Code,Machine_Name,Status from
Machine_Master where '" & combolinecode.Text & "' = Line_Code" )
我想从 1 =>更改Status
的值有效和 0 =>不活跃。
答案 0 :(得分:1)
您可以在几乎所有数据库中使用ANSI标准case
语句执行此操作:
select Machine_Code, Machine_Name,
(case when Status = 1 then 'active' else 'not active' end) as status
from Machine_Master
where '" & combolinecode.Text & "' = Line_Code";
我担心如果你使用VBA,你可能会使用Access,它有自己的方式:
select Machine_Code, Machine_Name,
iif(Status = 1, "active", "not active") as status
from Machine_Master
where '" & combolinecode.Text & "' = Line_Code";
答案 1 :(得分:0)
您可以使用case
:
select Machine_Code
, Machine_Name
, (case when Status = 1 then 'active' else 'not active' end) as Status
from Machine_Master
where '" & combolinecode.Text & "' = Line_Code