低手问题:如何保存数据库文件?如何只留下今天和昨天的数据?(100分)

  • 主题发起人 主题发起人 zhcg
  • 开始时间 开始时间
Z

zhcg

Unregistered / Unconfirmed
GUEST, unregistred user!
菜鸟问题,请各位仁兄不吝指教!
单机进销存数据库,涉及到每天要保存数据库文件。
1、请问使用什么命令可以保存数据表文件sample.db到软盘或硬盘其它位置中?
2、如何只显示最近两天的数据,以前的全部删除?如果今天的系统日期为'2001-10-15',
前天的日期怎么用表达式表示,我想用sql语言把前天以前的数据筛选出来,再删除,这
样语句应该怎样写?

 
1.用copyfile
The CopyFile function copies an existing file to a new file.

BOOL CopyFile(

LPCTSTR lpExistingFileName, // pointer to name of an existing file
LPCTSTR lpNewFileName, // pointer to filename to copy to
BOOL bFailIfExists // flag for operation if file exists
);


Parameters

lpExistingFileName

Points to a null-terminated string that specifies the name of an existing file.

lpNewFileName

Points to a null-terminated string that specifies the name of the new file.

bFailIfExists

Specifies how this operation is to proceed if a file of the same name as that specified by lpNewFileName already exists. If this parameter is TRUE and the new file already exists, the function fails. If this parameter is FALSE and the new file already exists, the function overwrites the existing file and succeeds.



Return Values

If the function succeeds, the return value is nonzero.
If the function fails, the return value is zero. To get extended error information, call GetLastError.

Remarks

Security attributes for the existing file are not copied to the new file.
File attributes (FILE_ATTRIBUTE_*) for the existing file are copied to the new file. For example, if an existing file has the FILE_ATTRIBUTE_READONLY file attribute, a copy created through a call to CopyFile will also have the FILE_ATTRIBUTE_READONLY file attribute. For further information on file attributes, see CreateFile.

2.var dToday:TDate;
sBeforeYesterday:string;
begin
dToday:=Date;
sBeforeYesterday:=FormatDateTime('yyyy-mm-dd',dToday-2);
qry.sql.clear;
qry.sql.add('delete from youtable where days<'+''''+sBeforeYesterday+'''');
qry.ExcSQL;
end;
就可删除.若为日期型.就要根据你的数据库里用什么函数了.db我不熟悉,例如ORACLE;
qry.sql.add('delete from youtable where days<to_date(''yyyy-mm-dd'','+''''+sBeforeYesterday+'''');
 
谢谢zhangkan为我解答了问题,我试一下再说。
 
第一个问题同意。
第二个问题用参数查询也可以。

parambyname('参数').asDatetime:=
strtodate(formatdatetime('yyyy-mm-',date)
+ inttostr(strtoint(formatdatetime('dd',date))-2);
 
多人接受答案了。
 
后退
顶部