with Query do begin
Close;
Sql.Clear;
Sql.Add('select max(tkdh) from xy_tk where substring(tkdh,1,8) = :number_head');
ParamByname('number_head') := 'TK'+FormatDateTime('yymmdd',Date);
open;
ls_tkdh := Fileds[0].AsString;
Close;
Sql.Clear;
Sql.Add('insert into xy_tk(tkdh,..)');
Sql.Add('values(:tkdh,..')');
if ls_tkdh = '' then
ParamByname('tkdh').Asstirng := 'TK'+FormatDateTime('yymmdd',Date)+'01';
else
parambyName('tkdh').Asstring :=Copy(ls_tkdh,1,8)+FormatFloat('00',
StrToInt(Copy(ls_tkdh,9,2))+1);
execSql;
end;
Close;
Sql.Clear;
Sql.Add('select max(tkdh) from xy_tk where substring(tkdh,1,8) = :number_head');
ParamByname('number_head') := 'TK'+FormatDateTime('yymmdd',Date);
open;
ls_tkdh := Fileds[0].AsString;
Close;
Sql.Clear;
Sql.Add('insert into xy_tk(tkdh,..)');
Sql.Add('values(:tkdh,..')');
if ls_tkdh = '' then
ParamByname('tkdh').Asstirng := 'TK'+FormatDateTime('yymmdd',Date)+'01';
else
parambyName('tkdh').Asstring :=Copy(ls_tkdh,1,8)+FormatFloat('00',
StrToInt(Copy(ls_tkdh,9,2))+1);
execSql;
end;
这句话有问题,执行时老是出错:field 'tkdh' not found .(注:tkdh 是char (10))
有谁可以帮我吗?先谢了!好象是max(tkdh),或substring(tkdh,1,8) 的问题!
实现很方便的
设计一个表,ReportNo
字段为
Flag varchar(20) 前缀标志
No int 序号
每次传入前缀,表里如果有,就加序号NO,如果没有就新建一个,定义序号NO=1
这样,什么样的单号都不用烦了,一个表里能同时实现很多单的自动编号