带有空值的case语句

时间:2018-06-18 18:38:22

标签: sql-server tsql

我正在写一个case语句,如果在我的查询中返回一条记录,则返回true或false。返回批号,它是True,当没有返回批号时,它是假的。当没有记录返回时,我一直空白。真实的一面效果很好。我希望它在没有返回记录时返回false。我确信这很简单。提前谢谢。

>>> a = set(s1r1[0])
>>> b = set(s1r1[1])
>>> uniq = a.union(b) - a.intersection(b)
>>> uniq    
{8, 1, 3, 5}

3 个答案:

答案 0 :(得分:1)

尝试删除where LOT_0 ='17-WA411-014'

select case when LOT_0 = '17-WA411-014' then 'True' else 'False' end 
from  [x3v7].[LIVE].[STOLOT]
group by LOT_0

答案 1 :(得分:0)

只需删除您的where条款:

所以,它将是:

select LOT_0, (case when LOT_0 = '17-WA411-014' 
                    then 'True' else 'False' 
               end) 
from  [x3v7].[LIVE].[STOLOT]
group by LOT_0;

答案 2 :(得分:0)

IF EXISTS(SELECT 1
from [x3v7].[LIVE].[STOLOT] where LOT_0 ='17-WA411-014') select case when LOT_0 = '17-WA411-014' then 'True' else 'False' end from [x3v7].[LIVE].[STOLOT] where LOT_0 ='17-WA411-014' group by LOT_0 ELSE SELECT 'False'

希望低于一个帮助,

相关问题