常用存储过程4(K310。3版本获取物流新单据的编码)
Create Proc GetICBillNo
@billtype int,
@isuse bit,
@billno varchar(100) out
as
set @billno=''
select a.*,isnull(b.ftable,'') as ftable,isnull(e.ffieldname,'') as FieldName
into #tmp
from t_billcoderule a
left join t_option e on a.fprojectid=e.fprojectid and a.fformatindex=e.fid
Left OUter join t_checkproject b on a.fbilltype=b.fbilltypeid and a.fprojectval=b.ffield
where a.fbilltypeid = @billtype order by a.FClassIndex
declare @pid int,@pval varchar(20),@length int,@format varchar(20)
DECLARE cc CURSOR FOR
SELECT FProjectID, FProjectVal, FLength,FFormatIndex
FROM #tmp
ORDER BY FClassIndex
OPEN cc
FETCH NEXT FROM cc
INTO @pid,@pval,@length,@format
WHILE @@FETCH_STATUS = 0
BEGIN
if(@pid=1)
begin
set @billno=@billno+@pval
end
else if(@pid=3)
begin
declare @v varchar(100)
set @v='00000000000000000000000000000000000000000000000000000000'
set @billno=@billno+left(@v,@length-len(@pval))+@pval
end
FETCH NEXT FROM cc
INTO @pid,@pval,@length,@format
END
CLOSE cc
DEALLOCATE cc
if(@isuse=1)
Update t_billcoderule set FProjectVal=Cast(FProjectVal as int)+1 where fbilltypeid = @billtype and FProjectID=3
select @billno
GO
declare @no varchar(100)
Exec GetICBillNo 80,0,@no out
print @no
@billtype int,
@isuse bit,
@billno varchar(100) out
as
set @billno=''
select a.*,isnull(b.ftable,'') as ftable,isnull(e.ffieldname,'') as FieldName
into #tmp
from t_billcoderule a
left join t_option e on a.fprojectid=e.fprojectid and a.fformatindex=e.fid
Left OUter join t_checkproject b on a.fbilltype=b.fbilltypeid and a.fprojectval=b.ffield
where a.fbilltypeid = @billtype order by a.FClassIndex
declare @pid int,@pval varchar(20),@length int,@format varchar(20)
DECLARE cc CURSOR FOR
SELECT FProjectID, FProjectVal, FLength,FFormatIndex
FROM #tmp
ORDER BY FClassIndex
OPEN cc
FETCH NEXT FROM cc
INTO @pid,@pval,@length,@format
WHILE @@FETCH_STATUS = 0
BEGIN
if(@pid=1)
begin
set @billno=@billno+@pval
end
else if(@pid=3)
begin
declare @v varchar(100)
set @v='00000000000000000000000000000000000000000000000000000000'
set @billno=@billno+left(@v,@length-len(@pval))+@pval
end
FETCH NEXT FROM cc
INTO @pid,@pval,@length,@format
END
CLOSE cc
DEALLOCATE cc
if(@isuse=1)
Update t_billcoderule set FProjectVal=Cast(FProjectVal as int)+1 where fbilltypeid = @billtype and FProjectID=3
select @billno
GO
declare @no varchar(100)
Exec GetICBillNo 80,0,@no out
print @no