如题,大家帮忙啊。
流水号用作该记录的唯一标识。

解决方案 »

  1.   

    SQL Server可以增加一个字段,设为Identify属性,则它就会自动增加,且不重复。
      

  2.   

    可以假定搂住定义的流水好字段为B0101;表名字是B01;
    B0101字段的值为‘2003-03-21001’var str : string;      //用以存储生成的流水号;
        ado: tadoquery;
    begin
      ado := tadoquery.create(self); 
      try
        ado.connection := adoconnection1;
        ado.sql.text := 'select max(B0101) from B01 group by B01';
        ado.open;
        if strtodate(leftstr(ado.fieldbyname('B0101').asstring,10)) <> date() then
           begin
            str := datetostr(date()) + '001';
           end
        else begin
            str := rightstr(ado.fieldbyname('B0101').asstring,3);
            str := inttostr(strtoint(str) + 1);
            str := datetostr(date()) + str;               
        end;
      finally ado.free;
      end; 
    end;
      

  3.   

    我给你写个代码吧:我用的是DB2,
     //取得服务器的日期
      qry_cx.Close;
      qry_cx.SQL.Clear;
      qry_cx.SQL.Add('SELECT DISTINCT CURRENT_DATE FROM table1');
      qry_cx.Open;
      //显示出库单号
      qry_xxcx.Close;
      qry_xxcx.SQL.Clear;
      qry_xxcx.SQL.Add('SELECT MAX(AUTO_CODE) FROM table2 ');
      qry_xxcx.SQL.Add('WHERE SUBSTR(AUTO_CODE,1,6)=:Aauto_Code');
      qry_xxcx.ParamByName('Aauto_Code').AsString:=
      formatdatetime('YYYYMM',qry_cx.Fields[0].asdatetime);
      qry_xxcx.Open;
      if qry_xxcx.Fields[0].AsString<>'' then
        lbl_ysdbh.Caption:=formatdatetime('YYYYMM',qry_cx.Fields[0].AsDATETIME)+
        copy(floattostr(strtofloat(copy(qry_cx.Fields[0].AsString,7,4))+10001),2,4)
      else
        lbl_ysdbh.Caption:=formatdatetime('YYYYMM',qry_cx.Fields[0].AsDATETIME)+
    '0001';
      

  4.   

    Thanks for all of you.