Function To Returns Max ID As Identity With Table Name and Field Name As Parameter in SQL

Function To Returns Max ID As Identity With Table Name and Field Name As Parameter in SQL

 CREATE PROCEDURE [dbo].[aMaxId]  
  @TableName nvarchar(100),  
   @FieldName nvarchar(100) AS  
 DECLARE @sql nvarchar(4000)  
 SELECT @sql = ' SELECT IsNull(Max('+@FieldName+'),0)+1 as Maxi' +  
        ' FROM dbo.'+@TableName  
 EXEC sp_executesql @sql