如何自动生成编号??不重复的
KH090002.....KH090100......
09表示年份
顺便说一下,我找过别人的方法,开始如果删除就可能会出现重复。请问如何解决?

解决方案 »

  1.   

    HOW TO DO THAT?能具体说一下吗?
      

  2.   

    var
    i:integer;
    curdate:string;
    begin
    adodataset1.open;
    for i:=0 to adodataset1.recordcount do
    begin
    curdate:=FormatDatetime('yy',now);
    //adodataset1.Append;
    edit1.Text:='kh'+curdate+'-00'+inttostr(i+1);
    next;
      

  3.   

    看不明白,KH090002是固定长度吗?如果是固定长度,KH099999的下一个如何表示?
      

  4.   

    'Select Max(ID) from 表......
      

  5.   

    不正真删除,加个删除字段就行啦.到时用一个view就行了
      

  6.   


    CREATE proc sp_GenerateDocCode @form_id int, @doc_code nvarchar(20) output
    as 
    declare
      @flow_num nvarchar(6),
      @flow_num_length int--更新流水号
    update sys_eform
    set flow_num = flow_num + 1 
    where form_id = @form_id and convert(nvarchar(6), flow_date, 112) = convert(nvarchar(6),getdate(), 112)--初始流水号
    update sys_eform
    set flow_date = getdate(), flow_num = 1 
    where form_id = @form_id and convert(nvarchar(6), flow_date, 112) <> convert(nvarchar(6),getdate(), 112)select @flow_num = convert(nvarchar(6), flow_num), @flow_num_length = flow_num_length
    from sys_eform where form_id = @form_id
    while (len(@flow_num) < @flow_num_length) begin
      set @flow_num = '0' + @flow_num
    end--组合流水号
    select @doc_code = form_code_prefix + form_code_separator + convert(nvarchar(6), flow_date, 112) + form_code_separator + @flow_num from sys_eform where form_id = @form_idGO
      

  7.   

    function GetNextID: String;
    var
       strSql, strValue, strYY: String;
       Temp: Integer;
    begin
       with adoquery do
       begin
          try
             Close;
             SQL.Clear;
             strYY := FormatDateTime('yy', Now);
             strSql := 'Select Max(ID) from 表名';
             strSql := strSql + ' Where ID like ''%'  + strYY+ '%''';
             SQL.Add(strSql);
             Open;
             if adoquery.RecordCount = 0 then
                Result := 'KH'+ strYY + '0001'
             else
             begin
                strValue := Trim(adoquery.FieldByName('ID').AsString);
                if strValue = '' then
                   Result := 'KH'+ strYY + '0001'
                else
                begin
                   strValue := Trim(Copy(strValue, 5, 4));
                   Temp := StrToInt(strValue) + 1;
                   Result :=  'KH'+ strYY + Format('%.4d', [Temp]);
                end;
             end;
          except
             Result := 'KH'+ strYY + '0001';
          end;
       end;
    end;
      

  8.   

    adoquery.FieldByName('ID').AsString  有点小问题。提示 找不到Id 后来 改成ex..1000 (忘记了)就好了