title: Create a compatibility matrix
body: <p>I've got data as follows:</p>
  
  <pre><code>[attribute] [value]
  foo yellow
  foo green
  foo red
  foo blue
  foo orange
  foo cyan
  foo magenta
  foo white
  foo brown
  foo purple
  </code></pre>
  
  <p><a href="http://sqlfiddle.com/#!3/d41d8/12764/0" rel="nofollow">provided in this fiddle</a></p>
  
  <p>I'd like to transform data to a kind of frame for a compatibility matrix, which should look like ( cols and rows are based on attribute-values ):</p>
  
  <pre><code>        yellow green red blue orange cyan magenta white brown purple
  yellow    x
  green            x
  red                   x
  blue                      x
  orange                          x
  cyan                                  x
  magenta                                      x
  white                                               x
  brown                                                     x
  purple                                                          x
  </code></pre>
  
  <p>Same kinds of attributes should automatically be filled with <code>x</code>, all other combinations are set by the user later on. Since number of <code>values</code> per <code>attribute</code> may differ it would be nice if the transformation is done dynamically.</p>
  
  <p>I made some shots using pivot / unpivot but only got cols ans rows changed - so only went half ( or quarter ;) ) the way.</p>
  
  <p>Any help or tips are appreciated! </p>
  
  <p><strong>Edit</strong>: I've changed attribute-values of demo-data for better understanding. colors-values have been numbers before.</p>
  
  <p><strong>Edit2</strong>: According to and resulting of the updated answer of Stephan and the mentioned aim to get results dynamically, I added the following example-query. Perhaps someone can use it, having the same need. #data is a temp table providing the base data.</p>
  
  <pre><code>DECLARE     @SQL VARCHAR(MAX);
  SET         @SQL = 'SELECT ' + '?placeholder?' + ' as name, '
  SELECT @SQL = @SQL + case when row_number() over ( order by rand() ) &gt; 1 then ',' else '' end +  'case value when ''' + cast( d.value as nvarchar ) + ''' then 1 else 0 end as "' +  cast( d.value as nvarchar ) + '"' from #data as d;
  select @sql = @sql + ' from #data;'
  set @SQL = replace( @sql, '?placeholder?', 'value' );
  --select @SQL;
  exec ( @sql )
  </code></pre>