如题.

解决方案 »

  1.   

    if (datatable.Rows.Count>0){//你的代码}else{//}
      

  2.   

    这个我也知道,但我想简单点,有没有办法.比如在datatable.Compute("sum(je)", "")这个条件过滤这有没有办法处理?
      

  3.   

    select isnull(round(sum(hdje),0),0) hdje from JLZF_jg where cbdh='TJ01' and bh in (select bh from JLZF_jgT where zfqh <> 0 and zfqh =10) group by left(dh,1)
    这是我的SQL,在没加分组的时候没有符合条件的会给出一个0,但加了分组没有符合条件的时候就是空了.这里有没有办法让isnull()继续起作用?
      

  4.   

    select sum(isnull(round(hdje,0),0)) hdje from JLZF_jg where cbdh='TJ01' and bh in (select bh from JLZF_jgT where zfqh <> 0 and zfqh =10) group by left(dh,1)吧sum放外面
      

  5.   

    datatable.Compute("sum(je)", "je is not null")
      

  6.   

    无法计算。表达式“System.Data.FunctionNode”不是聚合。用楼上的方法报这个错.
    datatable.Compute("isnull(sum(je),0)", "") 也报同样的错.
      

  7.   

    select isnull(hdje,0) from (select isnull(round(sum(hdje),0),0) hdje from JLZF_jg where cbdh='TJ01' and bh in (select bh from JLZF_jgT where zfqh <> 0 and zfqh =10) group by left(dh,1))
      

  8.   

    if(dt!=buu && dt.Rows.Count>0)
     object o=dt.Compute("sum(je)", "je is not null")
      

  9.   

    感谢各位的帮助.
    select isnull(hdje,0) from (select isnull(round(sum(hdje),0),0) hdje from JLZF_jg where cbdh='TJ01' and bh in (select bh from JLZF_jgT where zfqh <> 0 and zfqh =10) group by left(dh,1))
    这个SQL报语法错误.服务器: 消息 170,级别 15,状态 1,行 1
    第 1 行: ')' 附近有语法错误。================================================
    if(dt!=buu && dt.Rows.Count>0)
     object o=dt.Compute("sum(je)", "je is not null")
    我就是不想麻烦因为如果这样的话我要改的地方很多.我希望直接在dt.Compute("sum(je)", "je is not null")
    这一句里解决,或者直接在SQL中为空变为0.谢谢大家,请继续.
      

  10.   

    感谢各位的帮助.
    select isnull(hdje,0) from (select isnull(round(sum(hdje),0),0) hdje from JLZF_jg where cbdh='TJ01' and bh in (select bh from JLZF_jgT where zfqh <> 0 and zfqh =10) group by left(dh,1))
    这个SQL报语法错误.服务器: 消息 170,级别 15,状态 1,行 1
    第 1 行: ')' 附近有语法错误。================================================
    if(dt!=buu && dt.Rows.Count>0)
     object o=dt.Compute("sum(je)", "je is not null")
    我就是不想麻烦因为如果这样的话我要改的地方很多.我希望直接在dt.Compute("sum(je)", "je is not null")
    这一句里解决,或者直接在SQL中为空变为0.谢谢大家,请继续.
      

  11.   

    select isnull(hdje,0) from 
    (select round(sum(isnull(hdje,0)),0) as hdje from JLZF_jg where cbdh='TJ01' and bh in (select bh from JLZF_jgT where zfqh <> 0 and zfqh =10) group by left(dh,1)) a再试一下
      

  12.   

    搞不定,我试了好多种方法都无法通过sql语句当无数据时返回0,你还是用数据源判断吧
      

  13.   


    CREATE PROCEDURE usp_GetTotalAS 
     
          DECLARE @counts             int     --临时记录查询结果有否有记录
           DECLARE @sql                            nvarchar(500)
          DECLARE @ParmDefinition     nvarchar(500)
          SET @sql = N'SELECT @counts=COUNT(*) from from JLZF_jg where cbdh=''TJ01'' and bh in (select bh from JLZF_jgT where zfqh <> 0 and zfqh =10)';
                    SET @ParmDefinition = N'@counts  int  OUTPUT'; 
                    EXECUTE sp_executesql @sql, @ParmDefinition, @counts OUTPUT; 
          IF @counts <>0
               BEGIN
                    select round(sum(isnull(hdje,0)),0) as hdje from JLZF_jg where cbdh='TJ01' and bh in (select bh from JLZF_jgT where zfqh <> 0 and zfqh =10) group by left(dh,1)           
               END
          ELSE
               BEGIN
                    SELECT hdje=0
               ENDGO
      

  14.   

    我感觉是你的SQL语句有问题,先在数据库的客户端调试好你的SQL语句,如果有null,一般用ifnull(字段名,0)将null值转化为0,再计算就可以了.
    sum()不能应用于含有null值的列.这个问题在微软的官方网站上有,提出的解决办法也是修改查询语句,尽量不要返回null值,不好处理.