DECLARE @myvariable VARCHAR(100)
SET @myvariable = 'mytext'
SELECT Name FROM Customers AS @myvariable
How would one go about doing that?
Answer to Gareth:
This would allow me to retain the original name of the column when doing something like this:
declare @myvariable varchar(20)
set @myvariable='Name'
select case @myvariable when 'Name' then Name
when 'Id' then Id
end
as Name
from Customers
Right now, when the value of @myvariable changes, the colum name won’t, but I need it to be the same as @myvariable.
Something like this could work