--根據單位獲取系統編號 --創建人:朱保健 創建時間: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
本文介绍了一个SQL Server中用于生成单位特定自增序列号的存储过程。该过程通过获取当前日期并结合单位标识符来创建唯一的序列号,适用于需要唯一编号的应用场景。
680

被折叠的 条评论
为什么被折叠?



