title: TSql Case within Case
body: <p>I am trying to do a select statment in tsql with a case within a case. First is based on what the SearchField is. Next I need to do it based on the SearchOper. </p>
  
  <pre><code>    declare @searchField varchar(50)  
      declare @searchString varchar(50)
      declare @searchOper varchar(50)
  
      case @searchField
       when 'CompanyName' then
          case @searchOper
            when 'eq' then
              select * from tbl1 where CompanyName = @searchString
           when 'ne' then 
             select * from tbl1 where CompanyName &lt;&gt; @searchString
           end
       when 'StoreNum' then
          case @searchOper
            when 'eq' then
               select * from tbl1 where StoreNum = @searchString
            when  'ne' then
               select * from tbl1 where StoreNum &lt;&gt; @searchString
          end 
       end 
  </code></pre>
  
  <p>Note what I am trying to do is within the case statement do a select.</p>
  
  <p>I get a message saying Incorrect syntax near the keyword 'case'. </p>