Create proc sp_increment
(@TableName NVARCHAR(100),
@ColumnName NVARCHAR(100)
) AS
DECLARE @sql NVARCHAR(MAX)
SET @sql = 'SELECT Isnull(MAX(' + @ColumnName + '),0)+1 FROM ' + @TableName
print @sql
EXECUTE sp_executesql @sql
When i have no data in my table, it will return me 1
If i have exisitng data, then it will return me max+1
sp_increment 'tbl_user' ,'userid'