title: Concatenated distinct values with column names
body: <p>What is the most efficient way to get a concatenated list of distinct values from selected columns on SQL Server? </p>
  
  <pre><code>Col1    Col2    Col3 
  
  A       3       C23
  
  A       3       C32
  
  B       2       D12
  
  C       1       C23
  
  D       5       D12
  
  D       5       C32
  </code></pre>
  
  <p>My target output is a table as follows:</p>
  
  <pre><code>ColumnNames        DistinctValues
  
  Col1              {A,B,C,D}
  
  Col2              {1,2,3,5}
  
  Col3              {C23,C32,D12}
  </code></pre>
  
  <p>Would be great if I could specify which columns to be looked up.</p>