根据一定原则自动生成序列号的具体示例计算机等级考试
文章作者 100test 发表时间 2009:04:09 22:39:37
来源 100Test.Com百考试题网
需求:
◆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)
0select @itemcode=rtrim($[$43.5.0])
0select @y=substring(cast(year(getdate()) as varchar),3,2)
0select @m=cast(month(getdate()) as varchar)
0select @ml=len(Rtrim(@m))
if @ml=1
0select @m=’0’ @m
else 0select @m=@m
0select @t1=Ltrim(@y @m @itemcode)
0select @qty1=isnull(count(*),0) from OSRI where ItemCode=@itemcode and substring(IntrSerial,1,4)=@y @m
if Rtrim(@qty1)=’0’
begin
0select @tid=’001’
end
else
begin
0select @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
0select @tid=’001’
end
if len(Rtrim(@maxid))=1
begin
0select @tid=’00’ cast(Rtrim(@maxid) as char(1))
end
if len(Rtrim(@maxid))=2
begin
0select @tid=’0’ cast(Rtrim(@maxid) as char(2))
end
if len(Rtrim(@maxid))=3
begin
0select @tid=cast(Rtrim(@maxid) as char(3))
end
end
0select @t2=@t1 ’#’ @tid
0select @t2