我想在动态SQL查询中设置表名.
我尝试成功参数如下:
/* Using sp_executesql */ /* Build and Execute a Transact-sql String with a single parameter value Using sp_executesql Command */ /* Variable Declaration */ DECLARE @EmpID AS SMALLINT DECLARE @sqlQuery AS NVARCHAR(500) DECLARE @ParameterDefinition AS NVARCHAR(100) /* set the parameter value */ SET @EmpID = 1001 /* Build Transact-sql String by including the parameter */ SET @sqlQuery = 'SELECT * FROM tblEmployees WHERE EmployeeID = @EmpID' /* Specify Parameter Format */ SET @ParameterDefinition = '@EmpID SMALLINT' /* Execute Transact-sql String */ EXECUTE sp_executesql @sqlQuery,@ParameterDefinition,@EmpID
现在我想使用参数动态地使用TABLE NAME,但是我没有这样做.
请指导我