Cannot pass column name as parameter to sp_executesql
问题 I'm having trouble executing the below piece of code, it's giving me an error as below: Msg 102, Level 15, State 1, Line 3 Incorrect syntax near '@ST'. I can try implementing the login using dynamic SQL, but wanted to try the sp_executesql method. Please let me know if I'm having some syntax error or I'm not supposed to pass table names as parameters? DECLARE @SQL NVARCHAR(4000)= ''; SET @SQL = N'--INSERT INTO #missingkeys ( SOURCE_KEY,[ROWCOUNT] ) SELECT S.[SOURCE_KEY], COUNT(1) AS [ROWCOUNT