T-SQL:选择不等于值的行,包括空值 [英] T-SQL: select rows not equal to a value, including nulls

查看:32
本文介绍了T-SQL:选择不等于值的行,包括空值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何选择不等于值且在返回数据中包含空值的行?我试过了:

How do I select rows which don't equal a value and also include nulls in the returned data? I've tried:

SET ANSI_NULLS OFF
SELECT TOP 30 FROM Mails
WHERE assignedByTeam <> 'team01'

我想返回列 assignedByTeam 中没有team01"的行,但我也想要包含空值的结果.不幸的是,上面的代码不起作用(不返回空值).

I want to return rows which don't have 'team01' in column assignedByTeam but I also want results containing nulls. Unfortunately, the above code doesn't work (doesn't return the nulls).

我使用的是 MS SQL Server 2008 Express.

I'm using MS SQL Server 2008 Express.

推荐答案

尝试显式检查 NULL:

Try checking for NULL explicitly:

SELECT TOP 30 col1, col2, ..., coln
FROM Mails
WHERE (assignedByTeam <> 'team01' OR assignedByTeam IS NULL)

这篇关于T-SQL:选择不等于值的行,包括空值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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