title: Unpivot in SQL Server with where clause
body: <p>I have table <a href="https://i.stack.imgur.com/5SZHL.png" rel="nofollow noreferrer">diameter, modulus, number of teeth</a></p>
  
  <p>Step 1: I choose diameter (column d, mm)</p>
  
  <p>Step 2: I must choose two rows from table and transpose into two columns [number of teeth: z, modulus: m, mm] without value "0"</p>
  
  <p>For example: i am in need for using UnPivot in SQL for getting the rows converted in columns, but not able to do so with my unpivot query:</p>
  
  <pre><code>SELECT NewColumn1
  FROM tableTmp    
  UNPIVOT (NewColumn1 FOR allcols IN ([n2],[n3],[n4],[n5])) up1 // and where n1 = 0
  
  UNION All
  
  SELECT NewColumn2
  FROM tableTmp 
  UNPIVOT (NewColumn2 FOR allcols IN ([n2],[n3],[n4],[n5]) ) up2 // and where n1 = 6
  </code></pre>
  
  <p>Any help would be appreciated, i'm stuck and theres is not that much info on the web, thanks!</p>