SQL Server 2008 SELECT * FROM @variable?

前端 未结 6 1311
旧时难觅i
旧时难觅i 2020-12-19 03:53

It is possible?

DECLARE @vTableName varchar(50)

SET @vTableName = (SELECT TableName FROM qms_Types WHERE Id = 1)

SELECT * FROM @vTableName
<
6条回答
  •  南方客
    南方客 (楼主)
    2020-12-19 04:09

    The only way you can do this is through Dynamic SQL which refers to the practice of creating a T-SQL text and executing it using the sp_executesql (or simply exec)

    Here is a helpful link about dynamic sql The Curse and Blessings of Dynamic SQL.

    You should really think whether or not this is a case for dynamic sql or if there is another way for you to perform this operation.

提交回复
热议问题