[英]How to insert if statement in sql query at vb.net?
How to insert if/else in the query? 如何在查询中插入if / else?
This is my sqlcommand query : 这是我的sqlcommand查询:
sqlcommand ("select Machine_Code,Machine_Name,Status from
Machine_Master where '" & combolinecode.Text & "' = Line_Code" )
I wanna change the value of Status
from 1 => active and 0 => not active . 我想从1 => active和0 => not active更改
Status
的值。
You can do this with the ANSI standard case
statement in almost all databases: 您可以在几乎所有数据库中使用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";
I fear that if you are using VBA you might be using Access, which has its own way: 我担心如果您使用的是VBA,则可能会使用Access,它有自己的方式:
select Machine_Code, Machine_Name,
iif(Status = 1, "active", "not active") as status
from Machine_Master
where '" & combolinecode.Text & "' = Line_Code";
You can use case
: 您可以使用
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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.