日期:2014-05-18  浏览次数:20421 次

大家帮我看看如果使用这段存储过程,在事务并发的情况下有没有可能产生重复流水号的可能?
不用考虑生成的规则,就事务而言
CREATE       PROCEDURE   [dbo].[prGetDocNoCom]
@TableName   nvarchar(30),   @colName   nvarchar(50)   =   NULL,   @StartDate   nvarchar(10),   @OtherKey   nvarchar(4000),   @docLen   int   =   NULL,   @docNo   nvarchar(100)   OUTPUT
AS
DECLARE     @KeyName   nvarchar(50),   @Length   int
DECLARE   @StartValue   nvarchar(100)
DECLARE   @PrefixOrder   nvarchar(6)   ,   @IsAlpha   nvarchar(1),   @ViewRef   nvarchar(30),   @i   integer,@TempDocNo   nvarchar(20),@TempPrefix   nvarchar(20),   @ReGen   nvarchar(10)
DECLARE   @TempYear   nvarchar(3),   @TempRightYear   nvarchar(1),   @TempLeftYearInt   int,   @TempYearCharShift   int
DECLARE   @TempDayInt   int,   @TempDayCharShift   int
DECLARE   @StartDateValue   datetime
DECLARE   @RecCnt   int

DECLARE   @WaterNo   nvarchar(100),   @WaterNoDigit   integer,   @TempWaterNoDigit   integer,   @WaterNoChr   nvarchar(100),   @TempWaterCharShift   int,   @WaterNoCnt   int
DECLARE   @sqlWhereY   nvarchar(4000),   @sqlWhereM   nvarchar(4000),   @sqlWhereD   nvarchar(4000),   @sqlCommon   nvarchar(4000),   @sqlUpdateStart   nvarchar(4000),   @sqlSelectStart   nvarchar(4000),   @sqlSelectTable   nvarchar(4000)  

SET   @sqlWhereY   =   ' '
SET   @sqlWhereM   =   ' '
SET   @sqlWhereD   =   ' '

IF   @StartDate   =   ' '
SET   @StartDateValue   =   GetDate()
ELSE
SET   @StartDateValue   =   CAST(@StartDate   AS   datetime)

SET   @ReGen= ' '
SELECT   @PrefixOrder   =   PrefixOrder,   @IsAlpha   =   CAST(IsAlpha   AS   nvarchar(1)),   @ViewRef   =   IsNull(ViewRef,   TableName)   FROM   CommonStartPrefix   WHERE   TableName   =   @TableName   AND   IsNull(ColName,   ' ')   =   IsNull(@ColName,   ' ')


IF   @PrefixOrder   IS   NOT   NULL
BEGIN
SET   @i   =   1
SET   @TempDocNo   =   ' '
WHILE   @i   <   Len(@PrefixOrder)   +   1
BEGIN
IF   SubString(@PrefixOrder,@i,1)   =   '1 '
SELECT   @TempDocNo=@TempDocNo   +   Prefix1   FROM   CommonStartPrefix   WHERE   TableName   =   @TableName   AND   IsNull(ColName,   ' ')   =   IsNull(@ColName,   ' ')
IF   SubString(@PrefixOrder,@i,1)   =   '2 '
SELECT   @TempDocNo=@TempDocNo   +   Prefix2   FROM   CommonStartPrefix   WHERE   TableName   =   @TableName   AND   IsNull(ColName,   ' ')   =   IsNull(@ColName,   ' ')
IF   SubString(@PrefixOrder,@i,1)   =   '3 '
SELECT   @TempDocNo=@TempDocNo   +   Prefix3   FROM   CommonStartPrefix   WHERE   TableName   =   @TableName   AND   IsNull(ColName,   ' ')   =   IsNull(@ColName,   ' ')
IF   SubString(@PrefixOrder,@i,1)