SQL server NULL值问题 [英] SQL server NULL value problem

查看:152
本文介绍了SQL server NULL值问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我编写了以下SQL查询

I have written the following SQL query

select MT.TraAsset, MI.McMake, MI.McModel, MI.McSerial, MT.TraType, MT.TraDate, MT.TraFrom, MT.TraTo,
	F.cFloor_Descriptin,F.nFloor, C.cCmpName 
	from Smt_Mc_McTransfers MT
	left join Smt_Mc_McInformation MI on MI.McAsstNo=MT.TraAsset
	left join SpecFo.dbo.Smt_Floor F on MT.TranFloor=F.nFloor
	left join SpecFo.dbo.Smt_Company C on MT.TranCompanyID=C.nCompanyID
	where (MT.TraApprvBy is null) and (TraApprvDate is null) and MT.TranStatus <> 'Cancel'



没有行,但必须根据上述查询显示一行。

当我改变条件MT时.TranStatus为null然后显示一行。

在数据库中TranStatus = NULL。在此先感谢。


There brings no row but one row has to be shown on the basis of above query.
When I change the condition MT.TranStatus is null then the one row shows.
In the database TranStatus =NULL. Thanks in advance.

推荐答案

请参阅:Common错误(关于NULL使用) [ ^ ]。


Sumon562写道:
Sumon562 wrote:

(...)必须显示一行在上面的查询的基础上。

当我更改条件 MT.TranStatus为空然后显示一行。

(...) one row has to be shown on the basis of above query.
When I change the condition MT.TranStatus is null then the one row shows.





尝试以这种方式更改代码:



Try to change code this way:

where (MT.TraApprvBy is null) and (TraApprvDate is null) and COALESCE(MT.TranStatus,'') <> 'Cancel'





COALESCE [ ^ ]函数用<$ c $替换 NULL c>'default' value;)



COALESCE[^] function replaces NULL with 'default' value ;)


MT.TranStatus是NULL所以它不检查该行。如果你只是用其他东西编辑行,它将你必须在MT.TranStatus上插入任何状态而不是NULL
MT.TranStatus is NULL so it dont check for that row.If you simply edit the row with something else it will come.You have to insert any status on MT.TranStatus instead of NULL


这篇关于SQL server NULL值问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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