I have a sql that needs to be dynamic. The database name changes and so do the conditions.
Have the following value that I do a REPLACE for the variables inside the question marks and then use in aEXECUTE sp_executesql.
But I am having trouble with the ?TableName? because it is a declared table - @tablename.
How can i get this insert statement to work with my @tablename? Thanks.
'INSERT INTO ?TableName? SELECT name FROM ?DBName?.sys.tables WHERE [Type] = ''U'' ?Condition2? ?Condition3? ORDER BY name'