I want to try to get the structure of a table into a temp table, given the name of the table in a local var @TableName, along with two new columns. I have seen links (such as this) that have a similar situation, but they do not try to maintain the same structure. I have tried many variations of code (I know the current iteration is not good) and have found myself stuck.
declare @TableName as nvarchar(40) = 'TableVar'
declare @Query as nvarchar(250) = 'select * into #ModifiedTable
FROM (
SELECT *,''I'' creation_status, GETDATE() creation_timestamp
FROM '+@TableName+') SubQuery';
exec sp_executesql @Query
DROP TABLE #ModifiedTable