用Transact-SQL编程时,语句中的某一部分能否用变量代替(类似宏代换)。例如,下面的代码中,[email protected]:
DECLARE @TableName varchar(100)
SET @TableName='ExampleTable'
SELECT * FROM @TableName
------解决方案--------------------
- SQL code
DECLARE @TableName varchar(100) SET @TableName= 'ExampleTable ' exec('SELECT * FROM [email protected])