一种配件的收支存台账每一件配件都有唯一的编号。配件的入库一般是成批的,比如:从08758458222001——08758458222199 录入时也是这样从多少编号到多少编号。
配件的出库是10个为一批,比如:从08450——08460 录入到库中的数据也是如此。
编号怎么进行加法运算呀?如果能自动加,那后面的编号就不用输了,可以自动生成。查找功能:输入编号,可以查到入库和出库的情况(日期,值班人等)。可能很简单。大家给个思路啊!我是菜鸟!

解决方案 »

  1.   

    自增加一的实现if object_id('pubs..tb') is not null
       drop table tb
    gocreate table tb
    (
    id  int,
    name char(1)
    )
    insert into tb(id,name) values(1,'A')
    insert into tb(id,name) values(2,'B')
    insert into tb(id,name) values(3,'C')
    goselect id1 = identity(int,1,1) , * into test from tb
    select * from test
    drop table tb
    drop table testid1         id          name 
    ----------- ----------- ---- 
    1           1           A
    2           2           B
    3           3           C(所影响的行数为 3 行)如果ID不重复。还可以用下面的语句。
    select id1 = (select count(1) from tb where id <= a.id) , * from tb a
      

  2.   

    自增加序号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 行)
    */