BDRichardson
Programmer
Please would someone advise as to whether it is possible to do what I am attempting to with the following function? If so, would you kindly explain what I am doing wrong?
I simply want to declare table and column names to a function, and in return, get the next free number for the column, i.e. similar to an AutoNumber column, but controlled through a program using a function.
The function is:
I simply want to declare table and column names to a function, and in return, get the next free number for the column, i.e. similar to an AutoNumber column, but controlled through a program using a function.
The function is:
Code:
CREATE FUNCTION fnNextIdFromTable( @TableName VARCHAR( 128), @IdColumnName VARCHAR( 128))
RETURNS INT
AS
BEGIN
DECLARE @NextId INT
SELECT
@NextId = MAX( @IdColumnName) + 1
FROM
@TableName
RETURN @NextId
END