Quantcast
Channel: Transact-SQL forum
Viewing all articles
Browse latest Browse all 23857

Use dynamic sql to 'insert into @table'

$
0
0

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'


Viewing all articles
Browse latest Browse all 23857

Trending Articles