日期:2014-05-17 浏览次数:20467 次
CREATE TABLE [dbo].[test](
[id] [varchar](15) NULL
) ON [PRIMARY]
GO
Create procedure [dbo].[getIDonly]
(
@name varchar(2),
@re varchar (50) output
)
AS
BEGIN
begin TRANSACTION
declare @GD varchar(15) --固定左边
set @GD= (select @name+ cast (YEAR (getdate()) as varchar(4))+cast (MONTH (GETDATE ()) as varchar(2))+CAST (day(GETDATE()) as varchar(2)))
declare @DT varchar(5) ---动态右边
set @DT=(select right (left( max(CAST ( RIGHT (id,5) as NUMERIC(20,0))*100001+1),10),5) from test where id like @name +'%' )
if @DT is null
begin
set @DT='00001'
end
if @@error<>0
begin
rollback tran
end
commit tran
set @re= @GD+@DT
END
set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
go
ALTER PROCEDURE [dbo].[SOF_getmaxbh]
@biaoshi varchar(3), --单据类型标识
@addflag integer, --0,1 在前台使用;2 组成一个号返回,序号不加1(结转号),3 序号加 1 返回(单据编号);
@maxbh varchar(11)=NULL output --直接返回编号
AS
--内部变量声明
declare @recnum integer,
@rowcount integer
set @recnum=0
/*非事务内容执行*/
--每一过程拥有一唯一区界号,过程内的异常编号在此基础上增加
declare @errcode integer
set @errcode=1800
declare @return integer
set @return=0
--启动事务处理
declare @tran_point int --控制事务嵌套
set @tran_point=@@trancount --保存事务点
if @tran_point=0
begin tran tran_SOF_getmaxbh
else
save tran tran_SOF_getmaxbh
if