我有我CaseFiles
表csfl_CaseNo
列数据号是使用存储过程在SQL Server 2005中
00001/13-14
00002/13-14
00003/13-14
00004/13-14
00005/13-14
这里是我的存储过程来增加数量
ALTER PROCEDURE [dbo].[HLA_CaseNo](@strFnyr as nvarchar(5),@strSuffix as nvarchar(15) OUTPUT)
AS
BEGIN
--Declarations
declare @strSuffix1 as nvarchar(15)
declare @strTmp as nvarchar(5)
declare @intNew as int
--declare @strSql as nvarchar(2000)
set @strSuffix1 = null
--Process
begin
set @strSuffix1 = (select max(csfl_caseNo) from CaseFiles where csfl_Fynyr = @strFnyr)
--set @strPrf='QUT'
end
if @strSuffix1 is null
set @intNew = 1
else
set @intNew = cast(substring(@strSuffix1,0,5) as int) + 1
print 'The value of intNew ' + cast(@intNew as nvarchar(10))
set @strTmp = cast(@intNew as nvarchar(5))
set @strTmp = (select replicate('0',5-len(@strTmp)) + @strTmp)
set @strSuffix = @strTmp + '/' + @strFnyr
END
不增加我的任务是当我通过财政年度为13-14
它必须返回值为00006/13-14
,但它是ret改为使用00002/13-14
。
为什么会发生这种情况?请帮助
除了现有的错误,你也有一个多用户问题。当两个不同的用户调用这个存储过程时,他们将被分配相同的编号。如果您使用的是SQL Server 2012,请改用“SEQUENCE”。如果您使用的是早期版本,请使用“IDENTITY”。关于你的bug,不知道'csfl_Fynyr'字段里有什么是没有人能帮到的。同时,为什么不使用'PRINT'或'SELECT'来回显所有的变量值并检查它们。你可能有一个偏移错误或什么的。 – 2013-05-09 04:15:41