title: Loop through columns SQL
body: <p>I'm looking for a way to loop through the columns of a table to generate an output as described below.</p>
  
  <p>The table looks like that:</p>
  
  <pre>
  ID  Name     OPTION1 OPTION2 OPTION3 OPTION4 OPTION5
  1   MyName1  1       0       1       1       0
  2   MyName2  0       0       1       0       0
  </pre>
  
  <p>And the output looks like that:</p>
  
  <pre>
  MyName1 -> OPTION1, OPTION3, OPTION4
  MyName2 -> OPTION3
  </pre>
  
  <p>Any directions of doing this simply would be greatly appreciated. Otherwise, I suppose I'll have to use a cursor or a temporary table... The database engine is MSSQL. The reason I'm doing formatting at the database level is to feed its output into a limited programmable environment.</p>
  
  <p><strong>Update</strong>: the ouput can by in any form, a string or rows of strings.</p>
  
  <p><strong>Update</strong>: Would the be a way to accomplish that by building a string using @str = @str + ... ?</p>
  
  <p><strong>Update</strong>: I changed the output... this should be easier.</p>
  
  <p>Thanks!</p>