title: select name from customers as @myvariable // dynamic AS in sql
body: <pre><code>DECLARE @myvariable VARCHAR(100)
  SET @myvariable = 'mytext'
  
  SELECT Name FROM Customers AS @myvariable
  </code></pre>
  
  <p>How would one go about doing that?</p>
  
  <p><strong>Answer to Gareth:</strong>
  This would allow me to retain the original name of the column when doing something like this:</p>
  
  <pre><code>declare @myvariable varchar(20)
  set @myvariable='Name'
  
  select case @myvariable when 'Name' then Name
                          when 'Id' then Id
         end
            as Name
  
  from Customers
  </code></pre>
  
  <p>Right now, when the value of @myvariable changes, the colum name won't, but I need it to be the same as @myvariable.</p>