全局表应用

USE [DBCordBlood]
GO
/****** Object: StoredProcedure [dbo].[GetIntKey] Script Date: 05/29/2013 10:23:08 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[GetIntKey]
@KeyName nvarchar(50),
@KeyValue int OUTPUT
AS
BEGIN
declare @sql nvarchar(max)
set @sql = ''
SELECT @sql = 'select MAX(' + [name] + ') as MaxValue into ##tmpTable from '+ @KeyName
FROM sys.columns WHERE object_id = object_id(@KeyName) and column_id=1
EXECUTE(@sql)
SELECT @KeyValue=MaxValue+1 from ##tmpTable
DROP TABLE ##tmpTable
if (@KeyValue is null)
set @KeyValue =1
END

posted @ 2013-05-29 10:26  .NET Fans  阅读(143)  评论(0编辑  收藏  举报