I have a dynamic SQL statement to insert data into a memory table from a source table. The problem is, one of my variables, when run, evaluates out to a name of a column in the table I'm selecting from. I need it to be the column name, not whats in the column for my result.
The cursor @qa is holding the data item I want to include in the insert.
set @sql = 'INSERT INTO #MemoryTable (First_Name, Last_Name, Address_Line_1, Address_Line_2, City, State, ZipCode, Addressflag, HomePhone, eMail, emailflag, QuestionKey)
SEELECT FirstName, LastName, Address, Apartment, City, State, ZipCode, ''H'', PrimaryPhone, emailAddress, ''H'', ' + @qa + '
WHERE ' + @qa + ' <> ''No'''
So, instead of getting the column literal, I get the data item in the source table from that column. Is there any way to force the SELECT not to evaluate out the variable?