ERP系統(tǒng)各種單據(jù)流水號的產(chǎn)生方案
當前位置:點晴教程→知識管理交流
→『 技術(shù)文檔交流 』
ERP系統(tǒng)單據(jù)流水號是整個業(yè)務(wù)的一個重要憑證,并且都是唯一的。這些單據(jù)流水號可能包含的信息有日期信息、操作員信息等,而且每個客戶都有自己的單據(jù)編碼規(guī)范。本篇就介紹如何來產(chǎn)生這類單據(jù)流水號。主要應(yīng)用的還是字符串的拼接技術(shù)。
declare @ord_id varchar(20) select @ord_id=max(ord_id) from Toc_AdviseOrder if @ord_id is null set @ord_id='DJH10000001' else set @ord_id='DJH'+convert(varchar(8),right(10000000+convert(int,substring(@ord_id,5,11))+1,8)) 例如: create proc [dbo].CreateSequenceNumber @custId varchar(20) , --客戶編號 @typeFlag char(3), --業(yè)務(wù)類型 @outputId varchar(30) output --輸出單據(jù)號 as declare @l int, @Y char(2), @OutPutId varchar(20), --輸出客戶編號 @CustIdFormat varchar(20) select top 1 @l=len(custId) from customers where custUp='0' select @Y=Y from Years if @typeFlag='1' --訂貨單 begin if @custId='0' begin select @OutPutId=max(ord_id) from [order] where len(cst_id)=@l and substring(ord_id,1,6)='DHDA'+@Y and len(ord_id)=15 if @OutPutId is null set @OutPutId='DHDA'+@Y+'000000001' else set @OutPutId='DHDA'+@Y+convert(varchar(9),right(1000000000+convert(int,substring(@OutputId,7,9))+1,9)) end else --分銷 begin set @CustIdFormat = (select StringFormat from PosFormat where CustId = @custId) select @OutPutId=max(ord_id) from [order] inner join Customers on [order].cst_id=Customers.custId where if @OutPutId is null set @OutPutId='DHD'+@Y+@CustIdFormat+'00001' else set @OutPutId='DHD'+@Y+@CustIdFormat+convert(varchar(5),right(100000+convert(int,substring(@OutPutId,11,5))+1,5)) end end if @typeFlag='2' --發(fā)貨單 begin if @custId='0' begin select @OutPutId=max(sal_id) from sales where len(cust_id)=@l and substring(sal_id,1,6)='FHDA'+@Y and len(sal_id)=15 if @OutPutId is null set @OutPutId='FHDA'+@Y+'000000001' else set @OutPutId='FHDA'+@Y+convert(varchar(9),right(1000000000+convert(int,substring(@OutputId,7,9))+1,9)) end else --分銷 begin set @CustIdFormat = (select StringFormat from PosFormat where CustId = @custId) select @OutPutId=max(sal_id) from sales inner join Customers on sales.cust_id=Customers.custId where if @OutPutId is null set @OutPutId='FHD'+@Y+@CustIdFormat+'00001' else set @OutPutId='FHD'+@Y+@CustIdFormat+convert(varchar(5),right(100000+convert(int,substring(@OutPutId,11,5))+1,5)) end end if @typeFlag='3' --退貨單 begin if @custId='0' begin select @OutPutId=max(back_id) from Backs where len(cust_id)=@l and substring(back_id,1,6)='THDA'+@Y and len(back_id)=15 if @OutPutId is null set @OutPutId='THDA'+@Y+'000000001' else set @OutPutId='THDA'+@Y+convert(varchar(9),right(1000000000+convert(int,substring(@OutputId,7,9))+1,9)) end else --分銷 begin set @CustIdFormat = (select StringFormat from PosFormat where CustId = @custId) select @OutPutId=max(back_id) from Backs inner join Customers on Backs.cust_id=Customers.custId where if @OutPutId is null set @OutPutId='THD'+@Y+@CustIdFormat+'00001' else set @OutPutId='THD'+@Y+@CustIdFormat+convert(varchar(5),right(100000+convert(int,substring(@OutPutId,11,5))+1,5)) end end if @typeFlag='4' --入庫單 begin if @custId='0' begin select @OutPutId=max(rkd_id) from Rukudan inner join StorageType on Rukudan.Storagetype=StorageType.id and custId='0' where if @OutPutId is null set @OutPutId='RKDA'+@Y+'000000001' else set @OutPutId='RKDA'+@Y+convert(varchar(9),right(1000000000+convert(int,substring(@OutputId,7,9))+1,9)) end else --分銷 begin set @CustIdFormat = (select StringFormat from PosFormat where CustId = @custId) select @OutPutId=max(rkd_id) from Rukudan inner join StorageType on StorageType.id=Rukudan.StorageType where if @OutPutId is null set @OutPutId='RKD'+@Y+@CustIdFormat+'00001' else set @OutPutId='RKD'+@Y+@CustIdFormat+convert(varchar(5),right(100000+convert(int,substring(@OutPutId,11,5))+1,5)) end end if @typeFlag='6' --移庫單 begin if @custId='0' begin select @OutPutId=max(StockMoveID) from StockMove inner join StorageType on StockMove.StockOut=StorageType.id and custId='0' where and len(StockMoveID)=15 if @OutPutId is null set @OutPutId='ZKDA'+@Y+'000000001' else set @OutPutId='ZKDA'+@Y+convert(varchar(9),right(1000000000+convert(int,substring(@OutputId,7,9))+1,9)) end else --分銷 begin set @CustIdFormat = (select StringFormat from PosFormat where CustId = @custId) select @OutPutId=max(StockMoveID) from StockMove inner join StorageType on StockMove.StockOut=StorageType.id or stockMove.StockIn=StorageType.id where if @OutPutId is null set @OutPutId='ZKD'+@Y+@CustIdFormat+'00001' else set @OutPutId='ZKD'+@Y+@CustIdFormat+convert(varchar(5),right(100000+convert(int,substring(@OutPutId,11,5))+1,5)) end end if @typeFlag='7' --調(diào)貨單 begin set @CustIdFormat = (select StringFormat from PosFormat where CustId = @custId) select @OutPutId=max(ChId) from ChProduct inner join Customers on ChProduct.OutCustId=Customers.custId where if @OutPutId is null set @OutPutId='CHD'+@Y+@CustIdFormat+'00001' else set @OutPutId='CHD'+@Y+@CustIdFormat+convert(varchar(5),right(100000+convert(int,substring(@OutPutId,11,5))+1,5)) end if @typeFlag='8' --盤點單 begin if @custId='0' begin select @OutPutId=max(pandianId) from PanDian inner join StorageType on PanDian.StorageId=StorageType.id and custId='0' where if @OutPutId is null set @OutPutId='PDDA'+@Y+'000000001' else set @OutPutId='PDDA'+@Y+convert(varchar(9),right(1000000000+convert(int,substring(@OutputId,7,9))+1,9)) end else --分銷 begin set @CustIdFormat = (select StringFormat from PosFormat where CustId = @custId) select @OutPutId=max(pandianId) from PanDian inner join StorageType on StorageType.id=PanDian.StorageId where if @OutPutId is null set @OutPutId='PDD'+@Y+@CustIdFormat+'00001' else set @OutPutId='PDD'+@Y+@CustIdFormat+convert(varchar(5),right(100000+convert(int,substring(@OutPutId,11,5))+1,5)) end end if @typeFlag='9' --盈虧單 begin if @custId='0' begin select @OutPutId=max(yk_id) from YingKui inner join StorageType on YingKui.storageid=StorageType.id and custId='0' where if @OutPutId is null set @OutPutId='YKDA'+@Y+'000000001' else set @OutPutId='YKDA'+@Y+convert(varchar(9),right(1000000000+convert(int,substring(@OutputId,7,9))+1,9)) end else --分銷 begin set @CustIdFormat = (select StringFormat from PosFormat where CustId = @custId) select @OutPutId=max(yk_id) from YingKui inner join StorageType on StorageType.id=YingKui.storageid where if @OutPutId is null set @OutPutId='YKD'+@Y+@CustIdFormat+'00001' else set @OutPutId='YKD'+@Y+@CustIdFormat+convert(varchar(5),right(100000+convert(int,substring(@OutPutId,11,5))+1,5)) end end SET @outputId= @OutPutId 該文章在 2011/6/10 15:43:30 編輯過 |
關(guān)鍵字查詢
相關(guān)文章
正在查詢... |