在sql server上查询,给出true/false值 [英] query on sql server, giving true/false values

查看:1343
本文介绍了在sql server上查询,给出true/false值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我有以下代码:

suppose I have the following code:

select employer_id
from employer_tb


我希望这段代码为我提供一个true/false值.
如果owner_id为空,则为false,否则应提供真实值.
有人请教我如何?


I want this code to give me a true/false value.
false if employer_id is empty, otherwise it should give a true value.
someone please show me how?

推荐答案

您可以使用case语句来做到这一点:

you can do this with case statement:

SELECT   Employer =
      CASE employer_id
         WHEN '' THEN 'true'
         ELSE 'false'
      END
from employer_tb



假设数据为''且不为null.



this assums that data is '''' and not null.


您将必须提供@employer_id
的参数值
You will have to provide the parameter value for @employer_id
IF (select count(*) from   employer_tb   where employer_id = @employer_id)=1
BEGIN    PRINT 'true' END
ELSE 
BEGIN    PRINT 'false' END



如果在您的逻辑中,一个员工ID可以出现多次,则将上面的代码修改为:



If in your logic an employee id can appear more than once, modify the code above as:

(select count(*) from   employer_tb   where employer_id = @employer_id)>=1



希望对您有帮助



Hope this helps


这篇关于在sql server上查询,给出true/false值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆