根据一定原则自动生成序列号的具体示例

2008-08-18 13:25:03 北京时间

◆1、生产收货时,在数量处按CTRL+TAB,在序列号录入处按ShiFT+F2,能自动生成序列号;

 

◆2、生成原则如下:0703MG51T-09-S05-1200#001,其中0703为年月代码,MG51T-09-S05-1200为物料号,#号为分隔符,001为本月第一笔收货,以后自动加1。

 

我的语句如下:

declare @t1 as varchar(32)

declare @t2 as varchar(32)

declare @itemcode as varchar(20)

 

declare @y as varchar(20)

declare @m as varchar(20)

declare @ml as integer

 

declare @qty1 as varchar(3)

declare @maxid as varchar(3)

 

declare @tid as varchar(3)

 

select @itemcode=rtrim($[$43.5.0])

select @y=substring(cast(year(getdate()) as varchar),3,2)

select @m=cast(month(getdate()) as varchar)

select @ml=len(Rtrim(@m))

 

if @ml=1

select @m='0'+@m

else select @m=@m

 

select @t1=Ltrim(@y+@m+@itemcode)

 

select @qty1=isnull(count(*),0) from OSRI where ItemCode=@itemcode and substring(IntrSerial,1,4)=@y+@m

if Rtrim(@qty1)='0'

begin

select @tid='001'

end

else

begin

select @maxid=cast(isnull(max(cast(substring(IntrSerial,len(Rtrim(IntrSerial))-2,3) as float)),0) as float)+1 from OSRI where ItemCode=Rtrim(@itemcode) and substring(IntrSerial,1,4)=@y+@m

if len(Rtrim(@maxid))=0

begin

select @tid='001'

end

if len(Rtrim(@maxid))=1

begin

select @tid='00'+cast(Rtrim(@maxid) as char(1))

end

if len(Rtrim(@maxid))=2

begin

select @tid='0'+cast(Rtrim(@maxid) as char(2))

end

if len(Rtrim(@maxid))=3

begin

select @tid=cast(Rtrim(@maxid) as char(3))

end

end

select @t2=@t1+'#'+@tid

select @t2




发表评论

请文明参与讨论,禁止漫骂攻击。本站保留不刊登无关和不雅评论的权力。


用户名: 密码: 匿名

相关新闻
1. 确认已经安装了NT/2000和SQL Server的最新补丁程序,不用说大
在SQL Server中进行开发会让你身处险地,并且寻找快速解决方案。
本文说明向外扩展数据库系统的两个选项,从而实现更高的可扩展性
SQL Server 2005的新功能为动态管理对象,它们是在指定时间返回
本文从算法入手同时通过实例来讲解如何在SQL Server数据库中实现

广告
© 2008 The Czz5 Company. All Rights Reserved. 关于我们 - 联系我们 - 广告业务 - 网站地图 - 版权声明 - 友情连接 - 网站投稿 - 致信编辑