检查 SQL Server 中列的值是否为空

Check if a column#39;s value is null in SQL Server(检查 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 中列的值是否为空的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Execute complex raw SQL query in EF6(在EF6中执行复杂的原始SQL查询)
Hibernate reactive No Vert.x context active in aws rds(AWS RDS中的休眠反应性非Vert.x上下文处于活动状态)
Bulk insert with mysql2 and NodeJs throws 500(使用mysql2和NodeJS的大容量插入抛出500)
Flask + PyMySQL giving error no attribute #39;settimeout#39;(FlASK+PyMySQL给出错误,没有属性#39;setTimeout#39;)
auto_increment column for a group of rows?(一组行的AUTO_INCREMENT列?)
Sort by ID DESC(按ID代码排序)