表temp的Type字段大量重复吧?

解决方案 »

  1.   

    declear @bno='PC0001'
    update temp
    set Pno=(select max(Pno)+1 from products
    where type = (select type from temp where 订单编号=@bno))
    where 订单编号=@bno
      

  2.   

    Create Table Products(Pno Varchar(6), Type Int)
    GO
    Select 'Pc'+Right(10000+IsNull(Right(Max(Pno),4),0)+1,4) From Products Where Type='1'
    Insert Products Select 'Pc0001',1
    Select 'Pc'+Right(10000+IsNull(Right(Max(Pno),4),0)+1,4) From Products Where Type='1'
    GO
    Drop Table Products
    --Result
    Pc0001
    Pc0002
      

  3.   

    select max(Pno)+1 from products
    這樣應該不行的,Pno不是數字。