招考网【官方站】权威信息发布平台!

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

时间:2009-04-13 18:53来源: 作者: 点击:
全国计算机等级考试网提供计算机等级考试,计算机等级考试资讯快报,计算机等级考试报考指南,计算机等级考试证书查询等计算机等级考试资料
(责任编辑:86zhaokao.cn)
需求:
  ◆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
织梦二维码生成器
顶一下
(0)
0%
踩一下
(0)
0%
------分隔线----------------------------
发表评论
请自觉遵守互联网相关的政策法规,严禁发布色情、暴力、反动的言论。
评价:
表情:
用户名: 验证码:点击我更换图片
栏目列表
推荐内容