if exists (select * from sysobjects where name='proc_getbh')
drop procedure proc_getbh
go
create procedure proc_getbh @BM varchar(20)
as
declare @BH char(12)
declare @TODAY char(8)
begin
select @TODAY=convert(char(8),getdate(),112)
select @BH=BH from SEED where BM=@BM
if @BH is null or left(@BH,8)<>@TODAY
begin
select @BH=@TODAY+'0000'
end
select @BH=left(@BH,8)+ right('0000' + ltrim(convert(char(4),convert(int,right(@BH,4)))+1),4)
update SEED set BH=@BH where BM=@BM
select @BH AS BH
end