我现在有一个表,里面有日期字段(date),现在想先从日期字段中提取出月份,然后,再根据得出的月份值来查询数据,我的代码是这样的:
begin
t1:='6';
clientdataset1.Active:=false;
clientdataset1.CommandText:='select * from HUTAI_FEA where intostr(monthof(T))='''+t1+'''';
//clientdataset1.CommandText:='select * from HUTAI_FEA where T<'''+t1+'''';
//clientdataset1.CommandText:='select * from HUTAI_FEA where (select T FROM HUTAI_FEA)'+ inttostr(monthof(DateTime(select T FROM HUTAI_FEA)))  ;       //datetimepicker1.Date
clientdataset1.Active:=true;
end;

解决方案 »

  1.   

    ORACLE: TO_CHARbegin
    t1:='6';
    clientdataset1.Active:=false;
    clientdataset1.CommandText:='select * from HUTAI_FEA where TO_CHAR(T, 'FMMM')='''+t1+'''';
    //clientdataset1.CommandText:='select * from HUTAI_FEA where T<'''+t1+'''';
    //clientdataset1.CommandText:='select * from HUTAI_FEA where (select T FROM HUTAI_FEA)'+ inttostr(monthof(DateTime(select T FROM HUTAI_FEA)))  ;       //datetimepicker1.Date
    clientdataset1.Active:=true;
    end
      

  2.   

    inttostr是delphi的函数,不是sql的clientdataset1.CommandText:='select * from HUTAI_FEA where month(t)='+t1;
      

  3.   

    额我在用 二楼的语句的时候,为什么显示 FMMM未定义呢
      

  4.   


    不是Oracle就用3楼的吧