Si te explicas se entiende ;):
Código SQL:
Ver originalDECLARE @SQL nvarchar(MAX)
DECLARE @SELECT Nvarchar(MAX)
DECLARE @WHERE Nvarchar(MAX)
SET @KEY = '1'
SET @query= ' SELECT col1, col2, col3 FROM dbo.'
SET @WHERE= ' WHERE keycol = '
SET @SQL = @SELECT + quotename(@tblname) + @WHERE + @KEY
EXEC sp_executesql @SQL
SET @tblname='Nuevatabla'
SET @KEY = '2'
SET @SQL = @SELECT + quotename(@tblname) + @WHERE + @KEY
EXEC sp_executesql @SQL