表A里面有日期t_date这一列,Form里面有2个DateTimePicker控件(DTPBegin,DTPEnd),以DTPBegin内所选日期为起始日期,DTPEnd所选日期为结束日期作为查询条件
SQL语句怎么写

解决方案 »

  1.   

    我这样写的..说where附件有语法错误StrSql:=StrSql+'o_date between '+'#'+datetostr(DTPBegin.Date)+
                  '#'+' and '+'#'+datetostr(DTPEnd.Date)+'#';    StrSql:=copy(StrSql,5,255);
        with ADOQuery1 do
           begin
             sql.Clear;
             sql.Add('select * from orders where');
             sql.Add(StrSql);
             open;
           end;
      

  2.   

    query.sql.add('select * from A where t_date between ''' + DateToStr(DTPBegin.Date) + ''' and ''' + DateToStr(DTPEnd.Date) + '''');
      

  3.   

    sql.Add('select * from orders where ');
    where后加空格。
      

  4.   

    修改了一下...
    StrSql:=StrSql+'o_date between '+'#'+datetostr(datetimepicker1.Date)+
                  '#'+' and '+'#'+datetostr(datetimepicker2.Date)+'#';    StrSql:=copy(StrSql,5,255);
        with ADOQuery1 do
           begin
             sql.Clear;
             sql.Add('select p_no 产品编号,sum(o_num) 订货总数 from orders group by p_no where');
             sql.Add(StrSql);
             open;
           end;