| 導購 | 订阅 | 在线投稿
分享
 
 
 

根據一定原則自動生成序列號的具體示例

2008-08-16 07:22:25  編輯來源:互聯網  简体版  手機版  移動版  評論  字體: ||

需求:

◆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、生産收貨時,在數量處按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 [url=mailto:ItemCode=@itemcode]ItemCode=@itemcode[/url] 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
󰈣󰈤
王朝萬家燈火計劃
期待原創作者加盟
 
 
 
>>返回首頁<<
 
 
 
 
 熱帖排行
 
王朝網路微信公眾號
微信掃碼關註本站公眾號 wangchaonetcn
 
 
靜靜地坐在廢墟上,四周的荒凉一望無際,忽然覺得,淒涼也很美
© 2005- 王朝網路 版權所有