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

如何给空值赋值?
select sum(F_User_point) as gjpoint from TB_CDR where Calling_Station_Id='0411990005' 
and Called_Station_Id like '00%' 
and convert (varchar(10),convert(dateTime, h323_connect_Time),112) like '200803%' 
如何在上面的语句里的gjpoint如果为空的话,就给gjpoint赋一个0的值?

------解决方案--------------------
SQL code
select ISNULL(sum(F_User_point),0) as gjpoint FROM ...

------解决方案--------------------
select isnull(sum(F_User_point),0) as gjpoint from TB_CDR where Calling_Station_Id='0411990005'
and Called_Station_Id like '00%'
and convert (varchar(10),convert(dateTime, h323_connect_Time),112) like '200803%'
------解决方案--------------------
ISNULL(sum(F_User_point),0) as gjpoint
------解决方案--------------------
SQL code
select 'gjpoint'=isnull(sum(F_User_point),0)
from TB_CDR
where Calling_Station_Id='0411990005' and Called_Station_Id like '00%'  
    and convert (varchar(10),convert(dateTime, h323_connect_Time),112) like '200803%'

------解决方案--------------------
SQL code
select isnull(sum(F_User_point),0) as gjpoint 
from TB_CDR where Calling_Station_Id='0411990005' 
and Called_Station_Id like '00%' 
and convert (varchar(10),convert(dateTime, h323_connect_Time),112) like '200803%'  

--或者

select case when sum(F_User_point) is null then 0 else sum(F_User_point) end as gjpoint 
from TB_CDR where Calling_Station_Id='0411990005' 
and Called_Station_Id like '00%' 
and convert (varchar(10),convert(dateTime, h323_connect_Time),112) like '200803%'

------解决方案--------------------
解决就结贴。
------解决方案--------------------

用函数isnull(col,0)
------解决方案--------------------
探讨
解决了 谢谢各位了

------解决方案--------------------
探讨
SQL codeselect isnull(sum(F_User_point),0) as gjpoint
from TB_CDR where Calling_Station_Id='0411990005'
and Called_Station_Id like '00%'
and convert (varchar(10),convert(dateTime, h323_connect_Time),112) like '200803%'

--或者

select case when sum(F_User_point) is null then 0 else sum(F_User_point) end as gjpoint
from TB_CDR where Calling_Station_Id='0411990005'
and Called_Stati…