日期:2014-05-18  浏览次数:20424 次

这条语句哪里错了?谢谢大家帮看看!!!!
SQL code
select ISNULL(ClassName, '根分类') AS ClassName,ISNULL(NodeId,0) AS NodeId
from  Bst_ProClass where NodeId=some ( select ParentId from Bst_ProClass where NodeId=7)


上面NodeId=7是我的测试,它对应的ParentId=0 ,数据库里面没有以0 开头的NodeId纪录,但是想用ISNULL怎么解决不了?谢谢大家怎么处理这个问题的

------解决方案--------------------
SQL code
create table ta(classname varchar(10),parentid int,nodeid int)
insert into ta select 'a',1,2
insert into ta select 'b',0,7
go

if exists(select 1 from  ta where NodeId=some ( select ParentId from ta where NodeId=7))
     select ISNULL(ClassName, '根分类') AS ClassName,ISNULL(NodeId,0) AS NodeId
     from  ta where NodeId=some ( select ParentId from ta where NodeId=7)
else 
    select '根分类',0

drop table ta

/*
------ ----------- 
根分类    0

(所影响的行数为 1 行)
*/

------解决方案--------------------
some?
------解决方案--------------------
SQL code
select ISNULL(a.ClassName, '根分类') AS ClassName,ISNULL(a.NodeId,0) AS NodeId
from  Bst_ProClass a
right join Bst_ProClass t
on t.parentid = a.nodeid

------解决方案--------------------
改成以下代码应该可以

SQL code


select ISNULL(ClassName, '根分类') AS ClassName,ISNULL(NodeId,0) AS NodeId
from  Bst_ProClass where [color=#FF0000]isnull(NodeId,0)[/color]=some ( select ParentId from Bst_ProClass where NodeId=7)