对不起,忘记加“#”号了:select * from 物流表 where 日期 >= #2002-2-1 12:00:00# and 日期 <= #2002-2-1 18:00:00#
sqlTxt:='select * from table1 where dtt >= 2002-2-1 12:00:00 and dtt <= 2002-2-1 18:00:00'我试过了,不行,执行出错, 我还试过, sqlTxt:='select * from table1 where dtt >= '2002-2-1 12:00:00' and dtt <= '2002-2-1 18:00:00'';也不行。
var sqlTxt : string; begin sqlTxt := 'select * from table1 where dtt >=:1 and dtt <=:2 '; with ClientDataSet1 do begin Active := false; params.ParseSQL(sqlTxt,true); CommandText := sqlTxt; params[0].AsDateTime := StrToDateTime('2002-2-1 12:00:00'); params[1].AsDateTime := StrToDateTime('2002-2-1 18:00:00'); Active := true; end; end; 和后台数据库无关
sqlTxt := 'select * from table1 where dtt >=:1 and dtt <=:2 '; with ClientDataSet1 do begin Active := false; params.ParseSQL(sqlTxt,true); CommandText := sqlTxt; params[0].AsDateTime := StrToDateTime('2002-2-1 12:00:00'); params[1].AsDateTime := StrToDateTime('2002-2-1 18:00:00'); Active := true; end; 语句的执行顺序确实如此吗?
不对啊,我试过了,还是出错啊,提示异常EOLEException,出错信息:至少有一个参数没有被指定值!为什么???????我的程序大致如此: sqlTxt := 'select * from table1 where dtt >=:dtStart and dtt <=:dtEnd '; with ClientDataSet1 do begin Close; params.ParseSQL(sqlTxt,true); CommandText := sqlTxt; paramsByName('dtStart').AsDateTime := StrToDateTime('2002-2-1 12:00:00'); paramsByName('dtEnd').AsDateTime := StrToDateTime('2002-2-1 18:00:00'); Open; end;
select * from YouTable where DateTimeField between dtStart and dtEnd 如果使用delphi写的话 sqlTxt:='select * from table1 where dtt >= ''2002-2-1 12:00:00'' and dtt <= ''2002-2-1 18:00:00''';看仔细了,多写一个'
where 日期 >= #2002-2-1 12:00:00#
and 日期 <= #2002-2-1 18:00:00#
where dtt >= 2002-2-1 12:00:00
and dtt <= 2002-2-1 18:00:00'我试过了,不行,执行出错,
我还试过,
sqlTxt:='select * from table1
where dtt >= '2002-2-1 12:00:00'
and dtt <= '2002-2-1 18:00:00'';也不行。
sqlTxt : string;
begin
sqlTxt := 'select * from table1 where dtt >=:1 and dtt <=:2 ';
with ClientDataSet1 do
begin
Active := false;
params.ParseSQL(sqlTxt,true);
CommandText := sqlTxt;
params[0].AsDateTime := StrToDateTime('2002-2-1 12:00:00');
params[1].AsDateTime := StrToDateTime('2002-2-1 18:00:00');
Active := true;
end;
end;
和后台数据库无关
with ClientDataSet1 do
begin
Active := false;
params.ParseSQL(sqlTxt,true);
CommandText := sqlTxt;
params[0].AsDateTime := StrToDateTime('2002-2-1 12:00:00');
params[1].AsDateTime := StrToDateTime('2002-2-1 18:00:00');
Active := true;
end;
语句的执行顺序确实如此吗?
sqlTxt := 'select * from table1 where dtt >=:dtStart
and dtt <=:dtEnd ';
with ClientDataSet1 do
begin
Close;
params.ParseSQL(sqlTxt,true);
CommandText := sqlTxt;
paramsByName('dtStart').AsDateTime := StrToDateTime('2002-2-1 12:00:00');
paramsByName('dtEnd').AsDateTime := StrToDateTime('2002-2-1 18:00:00');
Open;
end;
access:需要用‘#’包围时间字符串。
sql server中不用。
where DateTimeField between dtStart and dtEnd
如果使用delphi写的话
sqlTxt:='select * from table1
where dtt >= ''2002-2-1 12:00:00''
and dtt <= ''2002-2-1 18:00:00''';看仔细了,多写一个'