好久没写帖子,纯手痒分享一小段。如果能帮到你一点点就很开心。
- DECLARE @NewFno nvarchar(100),
- @Str nvarchar(50),
- @maxNum int,
- @Fnum varchar(4)
- Set @Str='CKD-'+substring(convert(varchar(10),GETDATE(),112),3,6)
- Set @maxNum=(select isnull(MAX(REPLACE(编码字段,@str,'')),0)
- from 表名
- where substring(编码字段,1,LEN(@str))=@str
- and ISNUMERIC(REPLACE(编码字段,@str,''))=1 )
- set @Fnum=RIGHT('000'+CAST(@maxNum+1 AS varchar(4)),4)
- Set @Str=@Str+@Fnum
- SELECT @Str AS 出库单号
复制代码
|