Thread: MS SQL Server General Questions/Macro Substitution in Stored procedures

Macro Substitution in Stored procedures
CREATE PROCEDURE ACC_usp_Next_Number @cTableName char(40),@cField AS CHAR(40),@iNext int OUTPUT AS
DECLARE @cSQLString VARCHAR(256)

DECLARE @iNext integer -- or whatever type is @cField

SET @cSQLString = 'SELECT @iNext = MAX('+@cField+') FROM '+RTRIM(@cTableName)
EXEC(@cSQLString)
RETURN @iNext
GO