网络编程 | 站长之家 | 网页制作 | 图形图象 | 操作系统 | 冲浪宝典 | 软件教学 | 网络办公 | 邮件系统 | 网络安全 | 认证考试 | 系统进程
Firefox | IE | Maxthon | 迅雷 | 电驴 | BitComet | FlashGet | QQ | QQ空间 | Vista | 输入法 | Ghost | Word | Excel | wps | Powerpoint
asp | .net | php | jsp | Sql | c# | Ajax | xml | Dreamweaver | FrontPages | Javascript | css | photoshop | fireworks | Flash | Cad | Discuz!
当前位置 > 网站建设学院 > 网络编程 > Delphi
Tag:注入,存储过程,分页,安全,优化,xmlhttp,fso,jmail,application,session,防盗链,stream,无组件,组件,md5,乱码,缓存,加密,验证码,算法,cookies,ubb,正则表达式,水印,索引,日志,压缩,base64,url重写,上传,控件,Web.config,JDBC,函数,内存,PDF,迁移,结构,破解,编译,配置,进程,分词,IIS,Apache,Tomcat,phpmyadmin,Gzip,触发器,socket
网络编程:ASP教程,ASP.NET教程,PHP教程,JSP教程,C#教程,数据库,XML教程,Ajax,Java,Perl,Shell,VB教程,Delphi,C/C++教程,软件工程,J2EE/J2ME,移动开发
本月文章推荐
.DELPHI面向对象支持特点--保护级.
.在Delphi中开发使用多显示器的应.
.DELPHI的奇异菜单的编写.
.向word文档中输出表格及图形.
.创建良好设计的代码(基于Delphi.
.LineDDA的一个例子.
.Delphi字符串函数大全.
.在Delphi中如何把数据库中的记录.
.用DLL方式封装MDI子窗体.
.Delphi使用技巧四则.
.delphi里播放flash.
.谈Delphi编程中“流”的利用(一).
.用DELPHI开发DirectX游戏.
.由数据库数据生成XML的方法(有源.
.安装程序打包interbase的方法.
.两种Delphi实现Singleton模式方法.
.如何获取自己在程序中运行的外部.
.术语VCL的变更:从VCL到CLX.
.Delphi7中存储unicode的BUG.
.在Delphi中使用动态图标.

自动编号的存储过程

发表日期:2006-2-4


 

CREATE PROCEDURE Get_BH @cL_MC char(20),@nL_Init Int AS
begin
  Declare @nL_CD Numeric(2,0),@cL_LSH char(20),@cL_LX Char(1),@nL_CDT Int,@nL_CDM int
  Declare LSHB_cursor Cursor For Select Cd,LSH,Lx From LSHB Where MC=@cL_MC
  Open LSHB_cursor
  Fetch Next From LSHB_Cursor into @nL_CD,@cL_LSH,@cL_LX
  If  @@FETCH_STATUS = 0
    begin
      Select @nL_CDM=Len(RTrim(Convert(Char(10),@nL_Init)))
      If  @cL_LX='1'
        begin      -- 前面四位为年 '2000'
          Select @nL_CDT=@nL_CD-4
          If  left(@cL_LSH,4)=convert(char(4),getdate(),102)  /*  年份相等,序号加 1   */
            begin
              Select @nL_CDM=Len(RTrim(Convert(Char(20),Convert(int,Right(@cL_LSH,16))+1)))
       Update LSHB set LSH=Left(@cL_LSH,4)+Replicate('0',@nL_CDT-@nL_CDM)+Rtrim(Convert(Char(20),Convert(int,Right(@cL_LSH,16))+1))
                where MC=@cL_MC
            End
          else
            If @nL_Init>1
               Update LSHB set LSH=replace(Convert(Char(4),getdate(),102),'.','')+Replicate('0',@nL_CDT-@nL_CDM)+Rtrim(Convert(Char(10),@nL_Init))
                 where MC=@cL_MC
            Else
              Update LSHB set LSH=replace(Convert(Char(4),getdate(),102),'.','')+Replicate('0',@nL_CDT-1)+'1'
                where MC=@cL_MC
        End
      If  @cL_LX='2'
        begin      -- 前面六位为年月 '200008'
          Select @nL_CDT=@nL_CD-6
          If  left(@cL_LSH,4)=convert(char(4),getdate(),102) AND Convert(int,substring(@cL_LSH,5,2))=DATEPART(month,getdate())
            /*  年月相等,序号加 1   */
            begin
              Select @nL_CDM=Len(RTrim(Convert(Char(20),Convert(int,Right(@cL_LSH,14))+1)))
       Update LSHB set LSH=Left(@cL_LSH,6)+Replicate('0',@nL_CDT-@nL_CDM)+Rtrim(Convert(Char(20),Convert(int,Right(@cL_LSH,14))+1))
                where MC=@cL_MC
            End
          else
            If @nL_Init>1
               Update LSHB set LSH=replace(Convert(Char(7),getdate(),102),'.','')+Replicate('0',@nL_CDT-@nL_CDM)+RTrim(Convert(Char(10),@nL_Init))
                  where MC=@cL_MC
            Else
               Update LSHB set LSH=replace(Convert(Char(7),getdate(),102),'.','')+Replicate('0',@nL_CDT-1)+'1'
                  where MC=@cL_MC
        End
      If  @cL_LX='3'
        begin   -- 前面八位为年月日 '20000910'
          Select @nL_CDT=@nL_CD-8  
          If  left(@cL_LSH,4)=convert(char(4),getdate(),102) AND Convert(int,substring(@cL_LSH,5,2))=DATEPART(month,getdate())
              AND Convert(Int,SubString(@cL_LSH,7,2))=DatePart(Day,Getdate())
            Begin
              Select @nL_CDM=Len(Rtrim(Convert(Char(20),Convert(Int,Right(@cL_LSH,12))+1)))
              Update LSHB Set LSH=Left(@cL_LSH,8)+Replicate('0',@nL_CDT-@nL_CDM)+Rtrim(Convert(Char(20),Convert(Int,Right(@cL_LSH,12))+1))
                Where MC=@cL_MC 
            End
          Else
            If @nL_Init>1
              Update LSHB set LSH=replace(Convert(Char(10),getdate(),102),'.','')+Replicate('0',@nL_CDT-@nL_CDM)+RTrim(Convert(Char(10),@nL_Init))
                where MC=@cL_MC
            Else
              Update LSHB set LSH=replace(Convert(Char(10),getdate(),102),'.','')+Replicate('0',@nL_CDT-1)+'1'
                where MC=@cL_MC
        End
      If  @cL_LX='4'
        begin      -- 前面四位为年 '00' ,年用两位表示
          Select @nL_CDT=@nL_CD-2
          If  left(@cL_LSH,2)=convert(char(2),getdate(),2)  /*  年份相等,序号加 1   */
            begin
              Select @nL_CDM=Len(RTrim(Convert(Char(20),Convert(int,Right(@cL_LSH,18))+1)))
       Update LSHB set LSH=Left(@cL_LSH,2)+Replicate('0',@nL_CDT-@nL_CDM)+Rtrim(Convert(Char(20),Convert(int,Right(@cL_LSH,18))+1))
                where MC=@cL_MC
            End
          else
            If @nL_Init>1
               Update LSHB set LSH=replace(Convert(Char(2),getdate(),2),'.','')+Replicate('0',@nL_CDT-@nL_CDM)+Rtrim(Convert(Char(10),@nL_Init))
                 where MC=@cL_MC
            Else
              Update LSHB set LSH=replace(Convert(Char(2),getdate(),2),'.','')+Replicate('0',@nL_CDT-1)+'1'
                where MC=@cL_MC
        End
      If  @cL_LX='5'
        begin      -- 前面六位为年月 '0008', 年用两位
          Select @nL_CDT=@nL_CD-2
          If  left(@cL_LSH,2)=convert(char(2),getdate(),2) AND Convert(int,substring(@cL_LSH,3,2))=DATEPART(month,getdate())
            /*  年月相等,序号加 1   */
            begin
              Select @nL_CDM=Len(RTrim(Convert(Char(20),Convert(int,Right(@cL_LSH,16))+1)))
       Update LSHB set LSH=Left(@cL_LSH,4)+Replicate('0',@nL_CDT-@nL_CDM)+Rtrim(Convert(Char(20),Convert(int,Right(@cL_LSH,16))+1))
                where MC=@cL_MC
            End
          else
            If @nL_Init>1
               Update LSHB set LSH=replace(Convert(Char(5),getdate(),2),'.','')+Replicate('0',@nL_CDT-@nL_CDM)+RTrim(Convert(Char(10),@nL_Init))
                  where MC=@cL_MC
            Else
               Update LSHB set LSH=replace(Convert(Char(5),getdate(),2),'.','')+Replicate('0',@nL_CDT-1)+'1'
                  where MC=@cL_MC
        End
      If  @cL_LX='6'
        begin   -- 前面六位为年月日 '000910'
          Select @nL_CDT=@nL_CD-6
          If  left(@cL_LSH,2)=convert(char(2),getdate(),2) AND Convert(int,substring(@cL_LSH,3,2))=DATEPART(month,getdate())
              AND Convert(Int,SubString(@cL_LSH,5,2))=DatePart(Day,Getdate())
            Begin
              Select @nL_CDM=Len(Rtrim(Convert(Char(20),Convert(Int,Right(@cL_LSH,14))+1)))
              Update LSHB Set LSH=Left(@cL_LSH,6)+Replicate('0',@nL_CDT-@nL_CDM)+Rtrim(Convert(Char(20),Convert(Int,Right(@cL_LSH,14))+1))
                Where MC=@cL_MC 
            End
          Else
            If @nL_Init>1
              Update LSHB set LSH=replace(Convert(Char(8),getdate(),2),'.','')+Replicate('0',@nL_CDT-@nL_CDM)+RTrim(Convert(Char(10),@nL_Init))
                where MC=@cL_MC
            Else
              Update LSHB set LSH=replace(Convert(Char(8),getdate(),2),'.','')+Replicate('0',@nL_CDT-1)+'1'
                where MC=@cL_MC
        End
    end
  CLOSE LSHB_cursor
  DEALLOCATE LSHB_cursor
  select LSH from LSHB where MC=@cL_MC
End            

GO

上一篇:《delphi高手突破》节选一 人气:3531
下一篇:《delphi高手突破》节选二 人气:3402
浏览全部Delphi的内容 Dreamweaver插件下载 网页广告代码 祝你圣诞节快乐 2009年新年快乐