我对SQL一点也不懂,
请大家帮偶写一个东东,然后再告诉我怎么用哈
描述:
prodserial是一个自动编号列(5位递增,根据sortid的不同递增)
比如,
sortid 为129
prodserial
00001
00002
....
sortid 为187
prodserial
00001
00002
....

解决方案 »

  1.   

    create table test(sortid int identity,prodserial as right(100000+sortid,5))
    insert  test  default values
    insert  test  default values
    insert  test  default valuesselect  * from testdrop table test
      

  2.   

    ‘根据sortid的不同递增’
    那为什么
    sortid 为129
    prodserial
    00001
    00002
    ....
    sortid 为187
    prodserial
    00001
    00002
    ....
    129和187不同才对呀
      

  3.   

    不是这样的create table test(
    id int identity
    sortid int ,
    ...                     --其它字段
    )
    go
    select sortid,(select count(*) from test where  sortid=a.sortid and id<=a.id) as prodserial
    from test a
    order by 1,2
      

  4.   

    select sortid,(select count(*) from test where  sortid=a.sortid and id<=a.id) as prodserial,
    ...          其它字段
    from test a
    order by 1,2
      

  5.   

    我最后要的是编号是sortid+prodserial