declare @a as varchar; set @a='TEST' select @a from x;
谢谢
相反,您可以这样做:
declare @a as varchar; set @a='TEST' declare @sql nvarchar(max) set @sql = 'select [' + replace(@a,'''','''''') + '] from x' exec sp_executesql @sql
但要小心,这是一个安全漏洞(sql-injection攻击),所以如果不能信任或很好地清理@a,则不应该这样做.