Check if a column#39;s value is null in SQL Server(检查 SQL Server 中列的值是否为空)
问题描述
不敢相信我坚持这个,但我如何检查我返回的值在 select 语句中是否为空
Can't believe I am stuck with this but how can I check that value I am returning is null in select statement
IF EXISTS(SELECT TU.Tagged FROM TopicUser TU
WHERE TU.TopicId = @TopicId and TU.UserId = @UserId)
BEGIN
--do stuff
END
TU.Tagged
的值是 NULL
但它确实进入了条件.心目中它不存在.
The value of TU.Tagged
is NULL
but yet it does go into the condition. In mind it does not exist.
推荐答案
看起来你需要这样的东西:
It looks like you need something like:
IF EXISTS(SELECT TU.Tagged
FROM TopicUser TU
WHERE TU.TopicId = @TopicId
AND TU.UserId = @UserId
AND TU.Tagged IS NOT NULL)
BEGIN
--do stuff
END
否则,您只会检查是否存在符合您条件的记录,但这些记录在 TU.Tagged
列中可能具有 NULL
值.
Otherwise, you're checking only if records meeting your criteria exist, but those records could have a NULL
value in the TU.Tagged
column.
这篇关于检查 SQL Server 中列的值是否为空的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:检查 SQL Server 中列的值是否为空


基础教程推荐
- 无法在 ubuntu 中启动 mysql 服务器 2021-01-01
- SQL Server 2016更改对象所有者 2022-01-01
- 如何在 SQL Server 的嵌套过程中处理事务? 2021-01-01
- SQL Server:只有 GROUP BY 中的最后一个条目 2021-01-01
- 在 VB.NET 中更新 SQL Server DateTime 列 2021-01-01
- 使用pyodbc“不安全"的Python多处理和数据库访问? 2022-01-01
- SQL Server 中单行 MERGE/upsert 的语法 2021-01-01
- ERROR 2006 (HY000): MySQL 服务器已经消失 2021-01-01
- Sql Server 字符串到日期的转换 2021-01-01
- 将数据从 MS SQL 迁移到 PostgreSQL? 2022-01-01