declare @activeNum int; declare @netbarNum int; select @activeNum=0,@netbarNum=0 ---在这赋个初始值if @withlevel='主管' begin select @activeNum=sum(A.activeNums) ,@netbarNum=sum(A.netbarNums) from SpreaderDteDinfo A inner join SpreaderContact C on A.userID=C.userid where A.weekid=@weekid and C.upuserid=@SpreadID if(@activeNum=null) beginset @activeNum=0;这里我指定了0,但是最后update的值还是空的,为什么? end if(@netbarNum=null)beginset @netbarNum=0; endprint @activeNum
if(@netbarNum=null) 改成:if(@netbarNum is null) 好像不可以直接用“=”和null进行比较吧,要用 "is"来比较
这样试一下: declare @activeNum int; declare @netbarNum int; if @withlevel='主管' begin select @activeNum=ISNULL(sum(A.activeNums),0) ,@netbarNum=ISNULL(sum(A.netbarNums),0) from SpreaderDteDinfo A inner join SpreaderContact C on A.userID=C.userid where A.weekid=@weekid and C.upuserid=@SpreadID end print @activeNum
declare @netbarNum int; select @activeNum=0,@netbarNum=0 ---在这赋个初始值if @withlevel='主管' begin select @activeNum=sum(A.activeNums) ,@netbarNum=sum(A.netbarNums) from SpreaderDteDinfo A inner join SpreaderContact C on A.userID=C.userid where A.weekid=@weekid and C.upuserid=@SpreadID if(@activeNum=null) beginset @activeNum=0;这里我指定了0,但是最后update的值还是空的,为什么? end if(@netbarNum=null)beginset @netbarNum=0; endprint @activeNum
好像不可以直接用“=”和null进行比较吧,要用 "is"来比较
declare @activeNum int;
declare @netbarNum int; if @withlevel='主管'
begin
select @activeNum=ISNULL(sum(A.activeNums),0) ,@netbarNum=ISNULL(sum(A.netbarNums),0)
from SpreaderDteDinfo A inner join SpreaderContact C on A.userID=C.userid
where A.weekid=@weekid and C.upuserid=@SpreadID
end
print @activeNum