Skip to content
Advertisement

Invalid Column Name using Dynamic SQL

I am attempting to use Dynamic SQL for the 1st time – Now i understand the gist of it to an extent however attempting to enter a parameter into a temp table using Dynamic SQL i am getting the “Invalid Column name” when i am simply try to enter this as text not intending to be a column.

On a side note its worth me mentioning i am running this on SQL Server 2005.

This is my executing query

Many thanks in advance.

Advertisement

Answer

If you want the dynamic SQL to treat your variable as a literal string and not a column name you’ll have to wrap it in single quotes:

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement