var
Year,Month,Day:word;
SqlText,DateStr:String;
begin
with Query1 do
begin
Sql.Clear;
DecodeDate(Now,Year,Month,Day);
DateStr:=''''+InttoStr(Year)+'-'+InttoStr(Month)+'-'+InttoStr(Day)+'''';
SqlText:='Select * from czx where DateTime';
SqlText:=SqlText+' between '+DateStr+' and DateAdd(ms,-2,DateAdd(dd,1,'+DateStr+'))';
Sql.Add(SqlText);
Prepare;
Open;
end;
end;
这断代码在Sqlserver7.0测试过。