自动生成html的方法:自动生成编号的方法



前言:
    用过许多序号思路方法,indentity 或 id ,都不好用,自己写了个,这个序号特点是:每次取相应表中系统当天最大序号,如果当天无记录,则自动生成个当天序号

1.建种子表,这个表用来保存各个表目前已使用到最大序号
--种子表
create table SEED (
BM  varchar(20) not null,   --表名
BH   varchar(12) not null,   --种子编号
constra PK_SEED primary key(BM)
)
go

2.当我们建个新表时,同时把这个表名记录到种子表中,如:
--向种子中表添加记录
insert o SEED (BM,BH) values(\'tablename\',\'200211070000\')
go

3.在数据库建存储过程,自动生成新编号,此编号取当天时间,所以许多时候查询某些天记录时,这个序号非常有用
--为参数传递来某个表自动生成编号
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
@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(,right(@BH,4)))+1),4)
update SEED BH=@BH where BM=@BM
select @BH AS BH
end

4.例子如下:
\'对表xxx自动生成新编号
rs=conn.execute(\"proc_getbh @BM=\'xxx\'\")
这样,rs(\"BH\")就是你得到新编号
Tags:  word自动生成目录 自动生成目录 自动生成编号 自动生成html的方法

延伸阅读

最新评论

发表评论