繁体   English   中英

如何在vb.net的SQL查询中插入if语句?

[英]How to insert if statement in sql query at vb.net?

如何在查询中插入if / else?

这是我的sqlcommand查询:

 sqlcommand ("select Machine_Code,Machine_Name,Status from
 Machine_Master where '" & combolinecode.Text & "' = Line_Code" )

我想从1 => active0 => not active更改Status的值。

您可以在几乎所有数据库中使用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";

您可以使用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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM