数据库中的有一个为字符和数字混合的字段(如以字符开头,数字结尾的字段)怎样才能使增加一条新记录的时候系统自动在该字段的结尾加1,比如:SQ-001,自动变为SQ-002),请各位高手告诉我,好么?最好把代码写出来,小弟感谢不尽啊!

解决方案 »

  1.   

    select count(*) from table where field like '...'得到一个总数,然后添加的时候加1就行了!
      

  2.   

    我是想最好能有个代码来实现这个问题,比如说在edit1.text中输入一个编号如SQ-001,点击按钮后edit1.text能自动变成SQ-002
      

  3.   

    看看我的代码,我是200603010001做编号的.如果你前面的字母都一致,那可以套用.if dm.ADOQuery4.RecordCount = 0  then
        begin
          num1 := formatdatetime('yy年MM月dd日',now);
          num2 := '001';
          edit16.Text := num1 + num2 ;
        end
      else if dm.ADOQuery4.RecordCount > 0 then
        begin
          DM.ADOQuery4.Close ;
          DM.ADOQuery4.SQL.Clear ;
          DM.ADOQuery4.SQL.Add('select max(消费单号) from account ');
          dm.ADOQuery4.Open;
          if dm.ADOQuery4.Fields[0].Value <> '' then
          begin
            num1 := formatdatetime('yy年MM月dd日',now);
            if copy(dm.ADOQuery4.Fields[0].Value,0,6) = formatdatetime('yy年MM月dd日',now) then
              begin
                i := strtoint(copy(dm.ADOQuery4.Fields[0].Value,7,3)) + 1;
                if length(inttostr(i)) = 1 then
                  num2 := '0' + '0' + inttostr(i)
                else if length(inttostr(i)) = 2 then
                  num2 := '0' + inttostr(i)
                else if length(inttostr(i)) = 3 then
                  num2 := inttostr(i)
              end
            else
               num2 := '001';
            edit16.Text := num1 + num2 ;
          end;
        end;