这个语句有什么问题?

sk_sakula 2010-07-06 09:58:44
select a.spbh ,a.spmch,a.shengccj,
c.kcshl as shl ,a.dw,
b.yanghulb as yanghffcsh
from spkfk a,stib..zhongy b,spkfjc c
where a.spid=b.spid and a.spid=c.spid and c.kcshl>0
and b.yanghulb <> '10天养护' and b.yanghulb <>'5天养护'


现在这个yanghulb这个字段有4个值,上面有2个还有 一般养护 和NULL
按理上面应该检索出不包含上面这2个字段的所有条目
但实际执行时只能检索出 一般养护的条目,不能检索出包含 NULL的条目
为什么呢?
...全文
133 17 打赏 收藏 转发到动态 举报
写回复
用AI写文章
17 条回复
切换为时间正序
请发表友善的回复…
发表回复
sk_sakula 2010-07-13
  • 打赏
  • 举报
回复
学习啦
samyou 2010-07-08
  • 打赏
  • 举报
回复
要加isnull判断的,否则没显示。
cxmcxm 2010-07-07
  • 打赏
  • 举报
回复
null字段与任何字段或值作比较都返回null
所以出不来,要出来null字段行
可加 is null条件
改为
(b.yanghulb <> '10天养护' and b.yanghulb <>'5天养护' or b.yanghulb is null)


xiaoxiao8372 2010-07-07
  • 打赏
  • 举报
回复
你把数据贴出来,我们才方便看啊!现在我只建议你用左连接!
dynamic8111 2010-07-07
  • 打赏
  • 举报
回复
select a.spbh ,a.spmch,a.shengccj,
c.kcshl as shl ,a.dw,
b.yanghulb as yanghffcsh
from spkfk a,stib..zhongy b,spkfjc c
where a.spid=b.spid and a.spid=c.spid and c.kcshl>0
and b.yanghulb <> '10天养护' and b.yanghulb <>'5天养护'
and isnull(b.yanghulb,'')
加上一条and isnull(b.yanghulb,'') 试试
htl258_Tony 2010-07-07
  • 打赏
  • 举报
回复
[Quote=引用 8 楼 kerafan 的回复:]
SQL code

NULL不等于任何值
当使用比较运算符时,NULL值已被排除
可以这样变通
isnull(b.yanghulb,'') <> '10天养护'
[/Quote]

这样处理后可行。
helinhai 2010-07-07
  • 打赏
  • 举报
回复
[Quote=引用 7 楼 xhfjy 的回复:]
引用 6 楼 zflydy 的回复:

回复一个就10分吗?高兴得不得了

N久没上CSDN了,发现现在居然要分了咯,以前我的分呢?
[/Quote]....
TheGodOfGods 2010-07-07
  • 打赏
  • 举报
回复
select a.spbh ,a.spmch,a.shengccj,
c.kcshl as shl ,a.dw,
b.yanghulb as yanghffcsh
from spkfk a,stib..zhongy b,spkfjc c
where a.spid=b.spid and a.spid=c.spid and c.kcshl>0
and (b.yanghulb is null or (b.yanghulb <> '10天养护' and b.yanghulb <>'5天养护'))


空值
空 (NULL) 值表示数值未知。空值不同于空白或零值。没有两个相等的空值。比较两个空值或将空值与任何其它数值相比均返回未知,这是因为每个空值均为未知。
ask_chang 2010-07-07
  • 打赏
  • 举报
回复
select a.spbh ,a.spmch,a.shengccj,
c.kcshl as shl ,a.dw,
b.yanghulb as yanghffcsh
from spkfk a,stib..zhongy b,spkfjc c
where a.spid=b.spid and a.spid=c.spid and c.kcshl>0

-------and isnull(b.yanghulb,'') in('10天养护','5天养护')
and b.yanghulb <> '10天养护' and b.yanghulb <>'5天养护'


测试一下
SQL77 2010-07-06
  • 打赏
  • 举报
回复
IF null =1
PRINT 'TRUE'
sk_sakula 2010-07-06
  • 打赏
  • 举报
回复
地下室

每天回帖即可获得10分可用分!小技巧:教您如何更快获得可用分
sk_sakula 2010-07-06
  • 打赏
  • 举报
回复
地板 回复内容太短了!
sk_sakula 2010-07-06
  • 打赏
  • 举报
回复
沙发 回复内容太短了!
老黎 2010-07-06
  • 打赏
  • 举报
回复

NULL不等于任何值
当使用比较运算符时,NULL值已被排除
可以这样变通
isnull(b.yanghulb,'') <> '10天养护'
xhfjy 2010-07-06
  • 打赏
  • 举报
回复
[Quote=引用 6 楼 zflydy 的回复:]

回复一个就10分吗?高兴得不得了
[/Quote]
N久没上CSDN了,发现现在居然要分了咯,以前我的分呢?
zflydy 2010-07-06
  • 打赏
  • 举报
回复
回复一个就10分吗?高兴得不得了
我没有吃饭 2010-07-06
  • 打赏
  • 举报
回复
用left join试试?

34,576

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧