有个表(Access的)有个时间字段Intime
我想删除Intime中 最早的时间-->最早时间+×天 之间的记录var
t1,t2:TdateTime;
sqlstr:string;
Daydiff:integer;
begin
with query1 do
begin
try
Close;
SQL.Clear ;
sqlStr:='select * from log order by inTime';
sql.add(sqlstr);
open;
t1:=strToDateTime(fieldbyName('Intime').asstring); // 最早的一个日志时间
t2:=incDay(t1,MAXDAYDIFF); // 当最早时间+最大允许时间间隔 sql.Clear;
sqlStr:='delete * from Log where inTime<#'+DateTimeToStr(t2)+'#';
showMessage(sqlstr);
SQL.add(sqlStr);
ExecSQL ;
Close;
=======这是我写的,错误,执行时说 #34:00 (就是时间的一部分)不是一个字段
要怎么写?
我觉得我写的这个超级麻烦
感觉直接用Access中的时间函数应该就可以解决,可是我不知道怎么写?一到时间查询我就蒙了。还有:
比如我某个字段值中含有逗号,
比如str='12,34' 我要把它插入到Access的表中,它会提示出错,就是因为多了那个, 怎么办啊?
谢谢
我想删除Intime中 最早的时间-->最早时间+×天 之间的记录var
t1,t2:TdateTime;
sqlstr:string;
Daydiff:integer;
begin
with query1 do
begin
try
Close;
SQL.Clear ;
sqlStr:='select * from log order by inTime';
sql.add(sqlstr);
open;
t1:=strToDateTime(fieldbyName('Intime').asstring); // 最早的一个日志时间
t2:=incDay(t1,MAXDAYDIFF); // 当最早时间+最大允许时间间隔 sql.Clear;
sqlStr:='delete * from Log where inTime<#'+DateTimeToStr(t2)+'#';
showMessage(sqlstr);
SQL.add(sqlStr);
ExecSQL ;
Close;
=======这是我写的,错误,执行时说 #34:00 (就是时间的一部分)不是一个字段
要怎么写?
我觉得我写的这个超级麻烦
感觉直接用Access中的时间函数应该就可以解决,可是我不知道怎么写?一到时间查询我就蒙了。还有:
比如我某个字段值中含有逗号,
比如str='12,34' 我要把它插入到Access的表中,它会提示出错,就是因为多了那个, 怎么办啊?
谢谢
==这个是比如我的一个浮点数是 f='12,34' (这个是我机子的毛病,不知道为什么浮点全是,而不是.)
然后我插入到表中:insert into tab1 values floatToStr(f)
然后它就出错了,我就不懂了
如果不用Delphi中的时间函数
直接用Access中的时间函数来Sql查询,怎么写?
另外:sqlStr:='insert into tab1(对应字段) values ('+floatToStr(f)+')'
这样子就行了,好像不能加上时间,不然就错了,只能DateTostr,不能DateTimeTostr
Access还是会说 逗号×××
'select * from aa where (EnterTime>='+''''+FormatDateTime('mm',EnterTimeDTP.DateTime)+
'/'+FormatDateTime('dd',EnterTimeDTP.DateTime)+'/'+FormatDateTime('yyyy',EnterTimeDTP.DateTime)+
' 00:00:00:00'+''''+') ';
Access:
decodeDate(DateTimePicker1.DateTime,yyyy,mm,dd);
tempsql:='select * from aa where 日期 Between '+'#'+inttostr(mm)+'/'+inttostr(dd)+'/'+inttostr(yyyy)+'# And ';
decodeDate(DateTimePicker2.DateTime,yyyy,mm,dd);
tempsql:=tempsql+'#'+inttostr(mm)+'/'+inttostr(dd)+'/'+inttostr(yyyy)+'#')