sql-server-2008 - SQL Server 2008 SELECT * FROM @变量?

标签 sql-server-2008 variables

有可能的?

DECLARE @vTableName varchar(50)

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

SELECT * FROM @vTableName

我有这个错误:

Msg 1087, Level 16, State 1, Line 3 Must declare the table variable "@vTableName".

最佳答案

简短答案:不可以。

长答案:Noooooooooooooooooooooooooooooooooooooooo。如果需要,可以使用动态SQL,但是如果您以某种方式事先不知道表名的方式来构造表,那么重新考虑架构可能会有所帮助。

这是学习如何使用动态SQL的重要资源:The Curse and Blessings of Dynamic SQL

关于sql-server-2008 - SQL Server 2008 SELECT * FROM @变量?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10030486/

相关文章:

mysql - 如何使用mysql中的聚合函数为变量赋值?

javascript - 在 redux 函数中重构变量

php - "Notice: Undefined variable"、 "Notice: Undefined index"、 "Warning: Undefined array key"和 "Notice: Undefined offset"使用 PHP

python - 获取 __init__ 变量

sql-server - 具有多个输出参数的 SQL Server 2008 存储过程

database - 查找存储过程的参数名称

sql-server-2008 - SQL Server 无法在日期上调用方法

SQL Server : get average per week for the past 30 weeks

python - 将变量与数字相乘时遇到问题

sql-server - 链接服务器之间的触发