title: How do I use T-SQL's Case/When?
body: <p>I have a huge query which uses <em>case/when</em> often. Now I have this SQL here, which does not work.</p>
  
  <pre><code> (select case when xyz.something = 1
   then
       'SOMETEXT'
   else
        (select case when xyz.somethingelse = 1)
        then
            'SOMEOTHERTEXT'
        end) 
  
        (select case when xyz.somethingelseagain = 2)
        then
            'SOMEOTHERTEXTGOESHERE'
        end)
   end) [ColumnName],
  </code></pre>
  
  <p>Whats causing trouble is <code>xyz.somethingelseagain = 2</code>, it says it could not bind that expression. xyz is some alias for a table which is joined further down in the query. Whats wrong here? Removing one of the 2 case/whens corrects that, but I need both of them, probably even more cases.</p>