我的表里有一个日期字段,为date,写了一个查询:
select * from zw_skd2 where date>=DateTimePicker1.date and date<=DateTimePicker2.date)
出现这样的错误:列前缀'DateTimePicker1'与查询中所用的表名或别名不匹配。
谢谢大家!

解决方案 »

  1.   

    var
      str:string;
    str:=Datetimetostr(Datetimepicker1.date);
    select * from zw_skd2 where date>=str and ....
      

  2.   

    不同数据库sql语句不一样,oracle中如下
    adoquery1.close;
    adoquery1.sql.clear;
    adoquery1.sql.add('select* from table where date<='+to_date(quotedstr(datetostr(datetimepicker1.date)),'yyyy-mm-dd'));
    adoquery1.open;
      

  3.   

    to ahpei(独来读网):
    出现同样的错误。
      

  4.   

    你把DATATIMEPICKER1转换成字符和日期直接比较即可
      

  5.   

    to dyf2001():
    我用的是sql server。
      

  6.   

    lihongyue(yue):
    SQL语句是string类型的。将控件的date转换为string类型.
      

  7.   

    应该这样写:'select * from zw_skd2 where date>='+#39+formatdate('yyyy-mm-dd',DateTimePicker1.date)+#39+' and date<='+#39+formatdate('yyyy-mm-dd',DateTimePicker1.date)+#39—————————————————————————————————
    ┏━★━━◆━━★━┓ 
    ♂欢|◢CSDN◣|使♂        ▲自由保存帖子,浏览,关注检测
    ┃迎|◥论坛助手◤|用┃        ▲完善的CSDN客户端工具
    ┗━☆━━◇━━━☆┛       ▲自动添加签名......让你更快,更爽,更方便地上CSDN...
    http://www.csdn.net/expert/topic/573/573604.xml
    http://www.chinaok.net/csdn/csdn.zip
      

  8.   

    我想问一下:1。你的zw_skd2表里有没有 DATE这一项?
    2。如果有的话:
    VAR
    str:array[0..1] of string;
    str[0]:=Datetimetostr(Datetimepicker1.date);
    str[1]:=Datetimetostr(Datetimepicker2.date);
    select * from zw_skd2 where date>='''+str[0]+''' and '''+date<=str[1]+'''
      

  9.   

    to ahpei(独来读网):
    但我的date是日期型的呀!这样做好像没有比较出来!
      

  10.   


    ShortDateFormat:='YYYY-MM-DD';//这里可以设置你需要的格式
    DateSeparator:='-';这两句放到主窗体的oncreate事件里。with adoquery1 do
    begin
      active:=false;
      sql.add('select * fromzw_skd2 where date>='+''''+datetostr(Datetimepicker1.date)+''''+' and '+''''+datetostr(Datetimepicker2.date)+'''');
      active:=True;
    end;
    end;