Generate Variables Through T-SQL
You can do something like this:

DECLARE @i INT = 1
DECLARE @totalvars INT = 5
DECLARE @newvar VARCHAR(50) = ''

WHILE @i &lt; @totalvars

BEGIN

SET @newvar = 'DECLARE @newvar' + CONVERT(VARCHAR(50), @i) + ' = ?;'

SET @i += 1

RAISERROR (@newvar, 0, 1) WITH NOWAIT;

END


So we're all clear, this won't create variables for you unless it's part of a larger block of dynamic SQL. You're probably better off using a temp table. But on the off chance you're using more dynamic SQL, you could use a loop like this to append the variable declarations just fine.