SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO

ALTER  Procedure GetMaxID
 /* Param List */
 @Table varchar(20),
 @col varchar(20),
 @MaxID bigint output
AS

/******************************************************************************
**  File:
**  Name: GetMaxID
**  Desc: 获得指定表的指定列的累加最大ID值
**
**  This template can be customized:
**             
**  Return values:
**
**  Called by:  
**             
**  Parameters:
**  Input @Table 表名      Output @MaxID 最大ID
**            @col 列名
**            ----------       -----------
**
**  Date: 06-7-13
*******************************************************************************
**  Change History
*******************************************************************************
**  Date:  Author:        Description:
**  --------  --------    -------------------------------------------
**   
*******************************************************************************/
set nocount on

 Declare @SelectString varchar(200)
 Set @SelectString='Insert into #temptable select  max('+@col+')  from  '  + @Table + ' WITH (TABLOCKX, HOLDLOCK) '
 Create Table #temptable (TempID bigint)
 Exec (@SelectString)
 Select @MaxID=TempID from #temptable
 If @MaxID Is Null Set @MaxID=0
 Set @MaxID=@MaxID+1
 Drop Table #temptable
 
set nocount on

GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO

相关文章:

  • 2021-08-20
  • 2022-12-23
  • 2021-12-08
  • 2022-12-23
  • 2022-12-23
  • 2021-12-17
  • 2022-12-23
猜你喜欢
  • 2022-02-17
  • 2022-02-24
  • 2022-12-23
  • 2022-12-23
  • 2021-06-08
  • 2022-02-14
相关资源
相似解决方案