start_date 和end_date为日期类型
要得到字段值end_time比start_date大而比end_date小的所有记录
filter语句应该怎么写?
另外下面的程序错哪里?
adoquery1.close;
adoquery1.sql.clear;
adoquery1.sql.add('select * from table1 where end_time>=start_date and
end_time<end_date');
adoquery1.execsql;
要得到字段值end_time比start_date大而比end_date小的所有记录
filter语句应该怎么写?
另外下面的程序错哪里?
adoquery1.close;
adoquery1.sql.clear;
adoquery1.sql.add('select * from table1 where end_time>=start_date and
end_time<end_date');
adoquery1.execsql;
end_time<'''+datetostr(end_date)+'''');
begin
filtered:= false;
filter:='(end_time <=' + QuotedStr(end_data) + ') and (start_time >='+ QuotedStr(start_data) + ')';
filtered:= True;
end;
如楼上。
adoquery1.close;
adoquery1.sql.clear;
adoquery1.sql.add('select * from table1 where end_time>='''+Datetostr(start_date)+''' and
end_time<'''+datetostr(end_date)+'''');
adoquery1.open;
begin
close;
sql.clear;
sql.add('select * from table1 where end_time begin :start_date and :end_start');
parameters.parambyname('start_date').asDatetime:=值
parameters.parambyname('end_date').asDatetime:=值
end;
adoquery1.sql.add('select * from table1 where end_time>='''+Datetostr(start_date)+''' and
end_time<'''+datetostr(end_date)+'''');
方法二:
adoquery1.sql.add('select * from table1 where end_time Between '''+Datetostr(start_date)+''' and '''+datetostr(end_date)+'''');
这两种方法都可以,你之所以出错是因为你没有在值前面加引号,让SQL无法识别你的字段类型。