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

各位大哥来看看这是什么问题。。
以下是我定义的几个变量,为什么@totalpersent这个变量没有打印出来呢?
SQL code

declare @box2persent float
        declare @box3persent float
        declare @box4persent float
        declare @box2realsentcount int
        declare @box3realsentcount int
        declare @box4realsentcount int
        declare @totalpersent int
        set @box2persent=40
        set @box3persent=50
        set @box4persent=90
        set @totalpersent=0


        select @box2realsentcount=realsendcount from @result
        where servertype=130
        select @box3realsentcount=realsendcount from @result
        where servertype=131
        select @box4realsentcount=realsendcount from @result
        where servertype=216
        set @box2realsentcount=@box2realsentcount*@box2persent/100
        set @box3realsentcount=@box3realsentcount*@box3persent/100
        set @box4realsentcount=@box4realsentcount*@box4persent/100

        set @totalpersent=@box2realsentcount+@box3realsentcount+@box4realsentcount

        print @totalpersent
        print @box2realsentcount
        print @box3realsentcount
        print isnull(@box4realsentcount,0)

结果:
     
(2 row(s) affected)

(1 row(s) affected)

(2 row(s) affected)
 
3648
3696
0




为什么@totalpersent这个变量的结果没有打印出来呢?
很费解。。


------解决方案--------------------
没看出啥问题啊
------解决方案--------------------
set @totalpersent=@box2realsentcount+@box3realsentcount+@box4realsentcount
可能是这里面某个变量的值为null,相加后的结果为null,所以print出来没有东西
像下面这样也是

declare @i int
select @i=1+null
print @i
------解决方案--------------------
+1
探讨

set @totalpersent=@box2realsentcount+@box3realsentcount+@box4realsentcount
可能是这里面某个变量的值为null,相加后的结果为null,所以print出来没有东西
像下面这样也是

declare @i int
select @i=1+null
print @i

------解决方案--------------------
探讨
set @totalpersent=@box2realsentcount+@box3realsentcount+@box4realsentcount
可能是这里面某个变量的值为null,相加后的结果为null,所以print出来没有东西
像下面这样也是

declare @i int
select @i=1+null
print @i

------解决方案--------------------
set @totalpersent=@box2realsentcount+@box3realsentcount+@box4realsentcount

确定上面几个变量的值不为空?也就是全都不是null?