生成化验单号的存储过程
化验单号是表AssayData 的一个字段assayNum,化验单号是自动生成的
例如:2008-12-12   单号0812120001、0812120002...
单号自动增加是根据数据库中的实际记录
还不太会写存储过程,麻烦谁给写写 
谢谢

解决方案 »

  1.   

    Id, FormatId, F1 ,F2
    Id序号我设了自动加一,FormatId我想他也象这样"SL000001",
    当Insert时就加1,FormatId我想他也能自动加一"SL000001","SL000002"...
    能用一条sql什么办法实现.最好不要用中间表。有什么好方法?
    谢谢!
    create table #test
    (id int identity,
    FormatId as 'SL'+right(10000000+id,6),
    F1 varchar(50))
    go
    insert #test(F1) select '1'
    union all select '2'
    select * from #testdrop table #test
    /*
    id          FormatId       F1   
    ----------- -------------- -----
    1           SL000001       1
    2           SL000002       2(所影响的行数为 2 行)
    */
      

  2.   

    create table #test
    (id int identity,
    FormatId as 'SL'+right(10000000+id,6),
    F1 varchar(50))
    go
    insert #test(F1) select '1'
    union all select '2'
    select * from #testdrop table #test
    /*
    id          FormatId      F1 
    ----------- -------------- -----
    1          SL000001      1
    2          SL000002      2(所影响的行数为 2 行)
    */
    up,学到了
      

  3.   


    --创建
    if   object_id('GetNumber')   is   not   null   drop proc GetNumber  
    go 
    create proc GetNumber(@date varchar(10),@Number varchar(100) output)
    as
      select @Number=right(replace(@date,'-',''),len(replace(@date,'-',''))-2)+right(1000000,6)
    go--调用
    declare @Number  varchar(100)
    declare @date varchar(10)
    select @date=convert(varchar(10),getdate(),20)
    exec GetNumber @date,@Number output
    select @Number供楼主参考