忘记了说采购订单表porder
billid,billcode,traderid

解决方案 »

  1.   


    --说明:  实现思路供参考,通用性需要楼主去修改,比如RIGHT的3是hardcode,
    --需要去换成表字段值。主要就是两步取BILLCODE。。
    create proc getnebillcode 
    (
    @tableid int,
    @billdate datetime ,
    @billcode char(32) output 
    )
    as
    --1.求最大MAXCODE 
    declare @maxcode int
    select @maxcode = max(right(billcode,3))+1 from porder WITH (ROWLOCK)
    --2.根据数字长度不同组合不同的BILLCODE
     declare @smaxcode varchar(3)
    select @smaxcode = cast(@maxcode as varchar(3))
     if (@maxcode) = 3
    begin
    select @billcode = 'PO'+'-'+select convert(varchar(10),@billdate,120)+@smaxcode
    end 
    ELSE if (@maxcode) = 2
    BEGIN
    select @billcode = 'PO'+'-'+select convert(varchar(10),@billdate ,120)+'0'+@smaxcode
     
    end if (@maxcode) = 1
    BEGIN
    select @billcode = 'PO'+'-'+select convert(varchar(10),g@billdate,120)+'00'+@smaxcode
    end 
      

  2.   

    create proc getnebillcode 
    (
    @tableid int,
    @billdate datetime ,
    @billcode char(32) output 
    )
    as
    --1.求最大MAXCODE 
    declare @maxcode int
    select @maxcode = max(right(billcode,3))+1 from porder WITH (ROWLOCK)
    --2.根据数字长度不同组合不同的BILLCODE
     declare @smaxcode varchar(3)
    select @smaxcode = cast(@maxcode as varchar(3))
     if (@maxcode) = 3
    begin
        select @billcode = 'PO'+'-'+select convert(varchar(10),@billdate,120)+'-'+@smaxcode
    end 
    ELSE if (@maxcode) = 2
    BEGIN
    select @billcode = 'PO'+'-'+select convert(varchar(10),@billdate ,120)+'-'+'0'+@smaxcode
          
    end if (@maxcode) = 1
    BEGIN
    select @billcode = 'PO'+'-'+select convert(varchar(10),g@billdate,120)+'-'+'00'+@smaxcode
    end