如何查询数据库中某一时间段内的数据?各位前辈,小第初学,多指教。
各位大哥,小弟现在练习的程序有个功能是查询某一时间段内的数据,同样的
一句语句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型的
请问是什么原因?
谢谢了!
问题点数:20、回复次数:4Top
1 楼xgqing(xgqing)回复于 2002-12-04 23:50:22 得分 10
改为sql.add('select * from attendance where io_time>''2002-11-01'' and io_time<''2002-12-04''')Top
2 楼DunDao(所有这一切都是会有报应的)回复于 2002-12-04 23:51:11 得分 5
sql.add('select * from attendance where io_time>''2002-11-01'' and io_time<''2002-12-04''');Top
3 楼filix(传说中的卷心菜)回复于 2002-12-05 02:53:29 得分 5
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'Top
4 楼nightroad(一年)回复于 2002-12-05 08:50:51 得分 0
sql.add('select * from attendance where io_time>'+#39+2002-11-01+#39+' and'+' io_time<'+#39+2002-12-04+#39);Top




