日期:2014-05-16 浏览次数:20548 次
CREATE proc [dbo].[GetMaxNo]
(@itemNo varchar(20) output,
@biaoshi varchar(10),
@ziduan varchar(20)
)
as
begin
set nocount on
declare @maxNo varchar(20),@i int,@tsql nvarchar(4000)
set @maxNo=@biaoshi+'_'+replace(convert(varchar(10),getdate(),120),'-','')
select @tsql=N'select @i=isnull(max(right('+@ziduan+',4)),0)+1 from TableNumble where '+@ziduan+' like '''+@maxNo+'%'' '
exec sp_executesql @tsql,N'@i int output',@i=@i output
set @maxNo=@maxNo+'_'+right('0000'+cast(@i as varchar),4)
select @tsql=N'update TableNumble set ziduan='''+@maxNo+''' where flag='''+@biaoshi+''
exec sp_executesql @tsql
set @itemNo=@maxNo
end
where flag='''+@biaoshi+''
where flag='''+@biaoshi+''''