title: How pass main table selected column value as sub query column name in SQL Server
body: <p>Is there any way to pass selected table column value to a subquery?</p>
  
  <p>As an example, I have a <code>Stock</code> table, it has some section stock simple A_Stock, B_Stock, C_Stock like...</p>
  
  <pre><code>| Item Code    | A_Stock  | B_Stock  | C_Stock 
  +--------------+----------+----------+---------
  | Item1        | 10       |  13      |   35    
  | Item2        | 15       |  20      |   45    
  | Item3        |  8       |   6      |   33    
  </code></pre>
  
  <p>And I select ItemCode and Section (A, B...) from that table Like </p>
  
  <pre><code>SELECT ItemCode, Section  
  FROM tableName
  
  | Item Code    | Section  
  +--------------+---------
  | Item1        | A       
  | Item3        | C       
  | Item2        | B       
  </code></pre>
  
  <p>Then I want to select Item wise Section stock</p>
  
  <p>Expected result</p>
  
  <pre><code>SELECT
      ItemCode, 
      (SELECT CONCAT(ST.SectionFrom, '_Stock') firstTable 
       WHERE ItemCode = ST.ItemCode) AS Stock
  FROM 
      secondTable ST
  
  | Item Code     | Stock 
  +---------------+-------
  | Item1         |  10   
  | Item3         |  33   
  | Item2         |  20  
  </code></pre>
  
  <p>But the actual result is:</p>
  
  <pre><code>| Item Code     | Stock    
  +---------------+----------
  | Item1         | A_Stock  
  | Item3         | C_Stock  
  | Item3         | B_Stock  
  </code></pre>
  
  <p>If anyone has a solution please help me.</p>