title: How to write a select Query inside a CASE condition in MS SQL
body: <p>I have an Sql Query. It does not have any compilation error but in runtime it shows<br />
  <code>Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, &lt;, &lt;= , &gt;, &gt;= or when the subquery is used as an expression.</code>    </p>
  
  <pre><code> SELECT a.UserID FROM USERGROUPS a WHERE a.GroupID IN 
                        (CASE WHEN @group_id IS NULL THEN (select groupid from usergroups) ELSE 
                         CASE WHEN @group_id=0 THEN (select groupid from usergroups  where userid = @userid)ELSE
                        @group_id END END )
  </code></pre>
  
  <p>Thanks in advance.</p>