ADOQuery1.SQL.Add('select sum(金额) as aa from qqb where ID='+FCID.Text+' and 年份= '+Fyear.Text+' and 月份='+Fmonth.Text);
这是我的查询语句!出现错误!其中ID为整型;年份、月份为浮点型!
我不知道ADOQuery这个控件设置变量怎么设置的!我知道DBQuery的变量是用Params设置的!请问各位给一种解决的方法!

解决方案 »

  1.   

    with ADOQuery1 do
    begin
      sql.clear;
      SQL.Add('select sum(金额) as aa from qqb where ID=:id and 年份=:Fyear and 月份=:Fmonth);
      adoquery1.Parameters.ParamByName('id').value:=...;
      adoquery1.Parameters.ParamByName('Fyear').value:=...;
      adoquery1.Parameters.ParamByName('Fmonth').value:=...;
      open;
    end;
      

  2.   

    with ADOQuery1 do
    begin
      sql.clear;
      SQL.Add('select sum(金额) as aa from qqb where ID=:id and 年份=:Fyear and 月份=:Fmonth);
      adoquery1.Parameters.ParamByName('id').value:=FCID.Text;
      adoquery1.Parameters.ParamByName('Fyear').value:=Fyear.Text;
      adoquery1.Parameters.ParamByName('Fmonth').value:=Fmonth.Text;
      open;
    end;
      

  3.   

    //ID应用"[]"括起来
    ADOQuery1.SQL.Add('select sum(金额) as aa from qqb where [ID]='+FCID.Text+' and 年份= '+Fyear.Text+' and 月份='+Fmonth.Text);
      

  4.   

    试试我的方法便于动态调试。
    希望能解决你的问题。//以下三个变量存放ID,年份,月份 (均为整型变量)
    m_id:=...;
    m_year:=...;
    m_month:=...;
    ADOQuery1.SQL.Add(format('select sum(金额) as aa from qqb where ID=%d and 年份=%d and 月份=%d',[m_id,m_year,m_month]));
      

  5.   

    ADOQuery1.SQL.Add('select sum(金额) as aa from qqb where ID='+FCID.Text+' and 年份= '+Fyear.Text+' and 月份='+Fmonth.Text+' group by 金额');
      

  6.   

    select sum(金额) as aa from qqb where ID='+FCID.Text+' and 年份= '+Fyear.Text+' and 月份='+Fmonth.Text
    语句没有错误
    可能发生在:1、FCID.Text,Fyear.Text,Fmonth.Text不是整型值整数建议使用spinEdit控件
    2、查询语句与数据库不对应
      

  7.   

    FCID.Text是什么类型??
    如是字符串,要有引号,你可以在执行前用对话框输出这个sql语句看一下.
      

  8.   

    但是这样出错啊!错误:''is not a vaild floating point value    不知道什么意思!倒!