2 transient006 transient006 于 2013.06.25 10:59 提问

sqlserver not in 查询结果处理的问题

我的目的是想查询没有父节点 也就是说是根节点

SELECT t1.Id FROM dbo.T_Code as t1 WHERE CodeTypeId='108' AND Name = '非业务'
and t1.Id in(select t2.ParentID from dbo.T_Code as t2 where CodeTypeId='108'AND Name = '非业务')

select t2.ParentID from dbo.T_Code as t2 where CodeTypeId='108'AND Name = '非业务'

查询结果:
NULL
00000000-0000-0000-0000-000000000959
00000000-0000-0000-0000-000000000960
SELECT t1.Id FROM dbo.T_Code as t1 WHERE CodeTypeId='108' AND Name = '非业务'
查询结果:
00000000-0000-0000-0000-000000000959
00000000-0000-0000-0000-000000000960
00000000-0000-0000-0000-000000000961
我的目的是查询出
00000000-0000-0000-0000-000000000961这条记录
但是这样结果却查询不出来

1个回答

transient006
transient006   2013.06.25 11:22
已采纳

查找不出来是因为 NULL 引起的
SELECT t1.Id FROM dbo.T_Code as t1 WHERE CodeTypeId='108' AND Name = '非业务'
and t1.Id not in(select t2.ParentID from dbo.T_Code as t2 where CodeTypeId='108'AND Name = '非业务' AND t2.ParentID is not null)
修改为这样就可以了

suannai0314
suannai0314 你可以点击左侧的√采纳一下哦
4 年多之前 回复
Csdn user default icon
上传中...
上传图片
插入图片