title: Dynamically add 50 columns to table variable
body: <p>I would like to add around 50 columns to table defined as variable. Names of those columns are coming from another table and basically they are just numbers - DEPA_KEY. (department key)</p>
  
  <p>Is it possible to add those columns dynamically with loop or something similar?</p>
  
  <p>Table defined as variable (here I would like dynamically add 50 columns):</p>
  
  <pre><code>DECLARE @USERS TABLE
  (
    USER_KEY INT,
    USDE_HSU DECIMAL(8,2)
  )
  </code></pre>
  
  <p>Query for all departments:</p>
  
  <pre><code>SELECT DEPA_KEY FROM CADEPA
  </code></pre>