一些东西
DECLARE @sqlTable Varchar(20) SET @sqlTable = 'SoMetableName' + ' ' + '20100526' SELECT * INTO quotename(@sqlTable) FROM SoMetableName
但我得到了
Incorrect Syntax near ‘@sqlTable’.
它只是维护小脚本的一部分,所以我不必担心注射.
DECLARE @MyTableName nvarchar(20); DECLARE @Dynamicsql nvarchar(1000); SET @MyTableName = "FooTable"; SET @Dynamicsql = N'SELECT * INTO ' + @MyTableName + ' FROM BarTable'; EXEC(@Dynamicsql);