DECLARE @myvariable VARCHAR(100)
SET @myvariable = 'mytext'
SELECT Name FROM Customers AS @myvariable
一个人会怎么做呢?
对 Gareth 的回答: 这将允许我在执行以下操作时保留列的原始名称:
declare @myvariable varchar(20)
set @myvariable='Name'
select case @myvariable when 'Name' then Name
when 'Id' then Id
end
as Name
from Customers
现在,当@myvariable 的值发生变化时,列名不会改变,但我需要它与@myvariable 相同。