日期:2014-05-18 浏览次数:20633 次
CREATE TABLE test ( id int NOT NULL PRIMARY KEY identity(1,1), OrderNumber nvarchar(50) ) insert into test values('2012HJLS1000000001') if(exists(select * from sysobjects where name='GetCode' )) drop proc GetCode go create proc GetCode @shuliang int as declare @i int declare @OrderNumber nvarchar(50) declare @bianliang nvarchar(50) set @i = 0 while @i < @shuliang begin select top 1 @OrderNumber=OrderNumber from test order by id desc set @bianliang=right(cast(right(@OrderNumber,10)+0000000001 as varchar),10) insert into test values('2012HJLS'+@bianliang) set @i = @i + 1 end go exec GetCode 10