...where 日期 between '2002-9-2' and '2003-5-8
解决方案 »
- 让button按钮默认回车键
- FastReport
- !!!火!!!
- 用鼠标点DBGRID时,怎得到点中哪一个?
- 如何将表的一个计算字段的值赋给它的实际字段?写在什么过程中?
- [江湖救急]谁能告诉我,怎样向一个Dos程序发送命令!
- 怎样分析其他程序的内存
- oracle导入一个dmp文件为何说什么该对象已存在,怎么解决啊?在线等待!!
- 讨论一下:Delphi的Dll是不是只是一种陪衬?并没有发挥出动态链接库的优势。
- 哪位大侠能够告诉我,我如何的把位图或图标文件存入SQL的图片字段中呢?
- 今天买碟时看到一张Delphi 6.6中文版,我以前怎么没过,有这个版本吗?
- 有没有哪位高手可以帮我写一个判断日期合法性的函数?
with datamodule2.Query_inventory do
begin
databasename:='case';
close;
sql.Clear;
sql.Add('select * from collect where date between #'''+datetostr(dtp_start.Date)+'''# and #'''+datetostr(dtp_stop.Date)+'''#');
prepare;
open;
end;
begin
databasename:='case';
close;
sql.Clear;
sql.Add('select * from collect where date between :date1 and :date2);
prepare;
params[0].asdatetime := dtp_start.date;
params[1].asdatetime := dtp_stop.date;
open;
end;
sql.Add('select * from collect where date between to_date('''+datetostr(dtp_start.Date)+''','yyyy-mm-dd') and to_date('''+datetostr(dtp_stop.Date)+''','yyyy-mm-dd)')';
...
begin
databasename:='case';
close;
sql.Clear;
sql.Add('select * from collect where date between :date1 and :date2);
prepare;
params[0].asdatetime := dtp_start.date;
params[1].asdatetime := dtp_stop.date;
open;
end;
begin
databasename:='case';
close;
sql.Clear;
sql.Add('select * from collect where date between #'+datetostr(dtp_start.Date)+'# and #'+datetostr(dtp_stop.Date)+'#');
prepare;
open;
end;
==============================
你的问题是多了几个单引号,##之间的不是字符串就行用参数当然可以,但是直接写sql语句的话,可移植性就强很多
begin
databasename:='case';
close;
sql.Clear;
sql.Add('select * from collect where date between #'''+Fromatdatetime('m"/"d"/"yyyy,dtp_start.Date)+'''# and #'''+Fromatdatetime('m"/"d"/"yyyy,dtp_stop.Date)+'''#');
prepare;
open;
end;
begin
databasename:='case';
close;
sql.Clear;
sql.Add('select * from collect where date between :StartDate and :EndDate')
ParamByName('StartDate').Value:=datetostr(dtp_start.Date);
ParamByName('EndDate').Value:=datetostr(dtp_stop.Date);
prepare;
open;
end;
begin
databasename:='case';
close;
sql.Clear;
sql.Add('select * from collect where date between :date1 and :date2);
prepare;
params[0].value := formatdatetime('yyyy-mm-dd',dtp_start.date);
params[1].value := formatdatetime('yyyy-mm-dd',dtp_stop.date);
open;
end;