以下sql可实现编码的自动生成(从1开始),并且保证基本连续,删除中间号还可以用此中间号
Select min(to_Number(col1))+1 from a
where to_Number(col1)+1 not in (Select to_Number(col1) from a)
and 1 in (Select to_Number(col1) from a)
如果允许用户修改,则必须在存盘之前select一下表,是否存在此编号。
下面的代码可以实现
var
year,month,day:word;
begin
DecodeDate(Now,year,month,day);
with ADOQ_tempdo
begin
Close;
SQL.Clear;
SQL.Add('select Max(zyh) from dyszxzzyd where zyh<>''无号'' and dwbh='+''''+DepotID+'''');
Open;
if ADOQ_temp.Fields[0].AsString='' then
zyh:=IntToStr(year)+'0001'
else
if (year*10000)>ADOQ_temp.Fields[0].AsInteger then
zyh:=IntToStr(year)+'0001'
else
zyh:=IntToStr(ADOQ_temp.Fields[0].AsInteger+1);
end;
end;
function NumNOInc(NumNO:String):String;
var
TotalLength,i:Integer;
Number:Int64;
ZeroNo:String;
begin
TotalLength:=Length(NumNo);
Number:=StrToInt64(NumNo);
Number:=Number+1;
ZeroNo:='';
for i:=0 to TotalLength-Length(IntToStr(Number))-1do
begin
ZeroNo:=ZeroNo+'0';
end;
NumNOInc:=ZeroNo+IntToStr(Number);
end;