根據課別實時生成系統單號 --存儲過程

--根據單位獲取系統編號 --創建人:朱保健  創建時間:20080617 -- Exec sp_Get_PaperNo  'LTH' CREATE   Procedure sp_Get_PaperNo     (  @PaperType nvarchar(50)     ) As         Declare @Month char(2),                       @year   char(4),                     @day    char(2),                     @add_qnty int         ------------------------------------------------------------          Select @day=convert(char(2),datepart(day,getdate()))          Select @Month=convert(char(2),datepart(m,getdate()))          Select @year =convert(char(4),datepart(Year,getdate()))          Set @add_qnty=0        Select  @add_qnty=isnull(( Select Qnty+1 From GetNumTab(nolock)   Where T_Month=convert(char(6), getdate(),12)  and UnitID=@PaperType),0)           Select getNum=  ltrim(rtrim(right(@year,2)))+ right('0'+ltrim(rtrim(@Month)),2)+ right('0'+ltrim(rtrim(@day)),2)                                 +right('00'+rtrim(ltrim(convert(char(5),case @add_qnty when 0 then 1 else @add_qnty end))),3) if exists (select UnitID from GetNumTab where UnitID =  @PaperType)  begin        Update GetNumTab Set Qnty=case @add_qnty when 0 then 1 else @add_qnty end ,T_month=convert(char(6), getdate(),12)        Where  UnitID=@PaperType end else begin insert into GetNumTab (  UnitID,  Qnty,  T_Month ) values (  @PaperType,  '1',  convert(char(6), getdate(),12) ) end

GO

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值