我正在尝试基于存储过程的结构/数据创建一个新表(此处写为参数化查询)。有没有办法做到这一点?
DECLARE @ColList VARCHAR(MAX), @SQLStatement VARCHAR(MAX)
DECLARE @TableName VARCHAR(128)
DECLARE @ExtraColList VARCHAR(MAX)
SET @ColList = ''
SET @TableName = 'History.AccountsDefaultFields'
SET @ExtraColList = 'HistDate, HistType, HistGuid, HistID'
SELECT @ColList = @ColList + Name + ' , ' FROM syscolumns WHERE id = OBJECT_ID(@TableName) AND NOT Name IN('HistDate', 'HistType', 'HistGuid', 'HistID')
SELECT @SQLStatement = 'SELECT ' + SUBSTRING(@ColList,1,LEN(@ColList)-1) + @ExtraColList + ' From ' + @TableName
EXEC(@SQLStatement)
以上是我尝试从中创建新表的代码。这是为了重新排序表结构以允许传统存储过程正常运行。我想用EXEC(@SQLStatement)
结果的结构和数据创建新表