I would like to assign a select value to a variable using sql string. Below is my code:
DECLARE @maxRow INT, @tableName NVARCHAR(128) = N'whatever';
select @maxRow=Max(id) from @tableName
But this throws an error:
Msg 1087, Level 16, State 1, Line 3
Must declare the table variable "@tableName".
Even though I did declare the variable.