我要求和,要满足两个条件,一个当前EDIT4.TEXT的内容,一个是数据表CHGS字段为负数,下面是我的代码会出错(就是CHGS负数的出错)请各位指点一下 
  with f_data.bill do 
      begin 
        close; 
        sql.Clear; 
        sql.Add('select sum(chgs) as aa from mybill where code=:code '); 
        sql.Add('and chgs <0'); 
        Parameters.ParamByName('code').Value:=edit4.Text; 
        open; 
      end; 
      label14.Caption:=floattostr(-f_data.bill.FieldByName('aa').Value)+'元';

解决方案 »

  1.   

     label14.Caption:=floattostr(-f_data.bill.FieldByName('aa').Value)+'元';
    这个负号是什么意思?如果只是想取value的负值,那就剩以-1
      

  2.   

    最下面    label14.Caption:=floattostr(-f_data.bill.FieldByName('aa').Value)+'元';不管他看上面的
      

  3.   

    不是,底下不会出问题,就是上面sql.Add('and chgs <0'); 这行如果不进就不出问题,关键是我要负值才统计,底下只是让负值显示要正
      

  4.   

    或者可以写成
            sql.Add('select sum(chgs) as aa from mybill where chgs <0 and code=:code '); 
    另外出错的时候,要看一下为什么会出错
    也许是chgs里面有NULL值,如果是mssql可以试着改成:
            sql.Add('select sum(isnull(chgs,0)) as aa from mybill where isnull(chgs,0) <0 and code=:code '); 
      

  5.   

    还是不行,提示 Could not convert variant of type(null) into type(double)
      

  6.   

    先查一下数据库当中有没有符合条件的内容.
    label14.Caption:=floattostr(-f_data.bill.FieldByName('aa').Value)+'元';
    这一条代码之前必须判断f_data.bill是否为eof
      

  7.   


    应该是label14.Caption:=floattostr(-f_data.bill.FieldByName('aa').Value)+'元';这句出的错,原因是'aa'字段有空值