各位大哥,小弟现在练习的程序有个功能是查询某一时间段内的数据,同样的
一句语句select * from attendance where io_time>'2002-11-01' and io_time<'2002-12-04'
在SQL SERVER查询分析器里执行能找到符合条件的记录,而在
with DM_main.query1 do
          begin
          close;
          sql.clear;
sql.add('select * from attendance where io_time>'2002-11-01' and io_time<'2002-12-04'');
          prepare;
          open;
          end;
里,执行时,却提示
Error] u_attendance.pas(307): Missing operator or semicolon
[Error] u_attendance.pas(307): Missing operator or semicolon
[Error] u_attendance.pas(307): Incompatible types: 'String' and 'Integer'
[Fatal Error] attendance.dpr(11): Could not compile used unit 'u_attendance.pas'
307行是sql.add('select * from attendance where io_time>'2002-11-01' and io_time<'2002-12-04'');io_time是datetime型的
请问是什么原因?
    谢谢了!

解决方案 »

  1.   

    改为sql.add('select * from attendance where io_time>''2002-11-01'' and io_time<''2002-12-04''')
      

  2.   

    sql.add('select * from attendance where io_time>''2002-11-01'' and io_time<''2002-12-04''');
      

  3.   

    query里面''''代表‘,你的语句应该改成
    sql.add('select * from attendance where io_time>'+''''+'2002-11-01'+''''+' and io_time<'+''''+'2002-12-04'+'''');
    这样的sql语句才是
    select * from attendance where io_time>'2002-11-01' and io_time<'2002-12-04'
      

  4.   

    sql.add('select * from attendance where io_time>'+#39+2002-11-01+#39+' and'+' io_time<'+#39+2002-12-04+#39);