主题:[讨论]急需求助;谢谢各位高手了
以下这个存储过程总是存在错误,好象出在把表中的一个最大值赋给一个变量时.
CREATE procedure add_billID
@account varchar(30),
@date datetime,
@billID varchar(30) output
As
Begin
set @billID = 'JH'+ Convert(varchar(20),Year(@date))
if Month(@date)<10
set @billID =@billID +'0'+ Convert(varchar(20),Month(@date))
else
set @billID =@billID +Convert(varchar(20),Month(@date))
if Day(@date)<10
set @billID = @billID +'0'+ Convert(varchar(20),Day(@date))
else
set @billID =@billID +Convert(varchar(20),Day(@date))
declare @var1 nvarchar (2048)
Declare @Id Int
Declare @Id1 Int
select @var1='selelct @Id=select max(billId) from '+'"'+@account+'"'+ '_M4'
exec(@var1)
if @Id is NUll
begin
set @billID = @billID +'00001'
end
else
begin
set @id1 = Convert(int,SUBSTRING(Rtrim(@Id),11,10))
if @id1<9
set @billID = @billID +'00'+Convert(varchar(20),@id1+1)
else if @id1 <99
set @billID = @billID +'0'+Convert(varchar(20),@id1+1)
else
set @billID = @billID + Convert(varchar(20),@id1+1)
end
end
GO
CREATE procedure add_billID
@account varchar(30),
@date datetime,
@billID varchar(30) output
As
Begin
set @billID = 'JH'+ Convert(varchar(20),Year(@date))
if Month(@date)<10
set @billID =@billID +'0'+ Convert(varchar(20),Month(@date))
else
set @billID =@billID +Convert(varchar(20),Month(@date))
if Day(@date)<10
set @billID = @billID +'0'+ Convert(varchar(20),Day(@date))
else
set @billID =@billID +Convert(varchar(20),Day(@date))
declare @var1 nvarchar (2048)
Declare @Id Int
Declare @Id1 Int
select @var1='selelct @Id=select max(billId) from '+'"'+@account+'"'+ '_M4'
exec(@var1)
if @Id is NUll
begin
set @billID = @billID +'00001'
end
else
begin
set @id1 = Convert(int,SUBSTRING(Rtrim(@Id),11,10))
if @id1<9
set @billID = @billID +'00'+Convert(varchar(20),@id1+1)
else if @id1 <99
set @billID = @billID +'0'+Convert(varchar(20),@id1+1)
else
set @billID = @billID + Convert(varchar(20),@id1+1)
end
end
GO