您的当前位置:我要购书网>在线阅读>Delphi/Perl

自动编号的存储过程

来源:互联网  作者:  发布:我要购物网收集整理  发布时间:2006-8-31 人气:177

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

相关文章
· 自动生成拼音(汉字反查到拼音)
· 自动调整listview标题头宽度的二种方法
· 自动循环播放的mp3播放器
· 自动化每日构建(三)用nant来完成.net工程的每日构建
· 自动截屏到文件的小程序
· 自动化每日构建(二)用ant来完成java工程的每日构建
· 自动建库的安装程序制作方法
· 自动建站.实现虚拟二级目录
· 自动循环播放的mp3播放器(续)
· 自动编号的存储过程
热点文章
%>
· creating user controls
· 提高fastreplace速度 (fstrrep.pas)
· asc ii 完整码表及简介
· 自动生成拼音(汉字反查到拼音)
· sql2000无法安装的解决办法
· 浏览器集成教学 自定义浏览器
· vc++技术内幕(第四版)笔记(第7章)
· mysql5.0中文乱码解决方案
· sql server日期计算
· vc下利用ado连接access数据库
 淘宝旺旺:我要购书网上书店『图书目录
本购书中心地址: 杭州市延安路111号清波商厦南楼D座(总部) 上海市闸北区老沪太路网上购书中心(沪部),  邮编:310002
电子邮件:books@51goushu.com  经营许可证编号:沪ICP备06038574号
版权所有 2003-2008 © All Rights Reserved .购书网