I am trying to execute this statement in sql server:
EXECUTE ('SELECT @lnRowIdMin = MIN(TMP_ROW_ID) FROM #' + @lvcBaseTable).
Here @lnRowIdMin
is declared as an integer variable and @lvcBaseTable
is declared as an varchar(255) variable in my original code.
Executing the original code throws the error for the above statement:
Must declare the scalar variable
Then I changed the statement to:
EXECUTE ('SELECT ' + @lnRowIdMin + ' = MIN(TMP_ROW_ID) FROM #' + @lvcBaseTable).
Now it throws this error: "Incorrect syntax near '='"