title: How can I rewrite this without using if statement?
body: <p>I want to rewrite this code without using any if statement.</p>
  
  <p>Is it possible to do that ?</p>
  
  <p>How can I use case or something else ?</p>
  
  <pre><code>IF @BrandFilter = ''
      BEGIN
          SELECT * FROM
          (
              SELECT
                  ROW_NUMBER() OVER(ORDER BY  
                  CASE WHEN @SortType = '1' THEN mt.Ad END ASC,
                  CASE WHEN @SortType = '2' THEN mt.Ad END DESC,
                  CASE WHEN @SortType = '3' THEN mt.Fiyat END ASC,
                  CASE WHEN @SortType = '4' THEN mt.Fiyat END DESC) AS RowNr, * 
              FROM @MainTable mt
              WHERE mt.Fiyat &gt; @MinPrice AND mt.Fiyat &lt; @MaxPrice     
          ) Result
          WHERE RowNr &gt; ((@PageNr-1) * 10) AND RowNr &lt;= ((@PageNr) * 10)  
      END
  ELSE
      BEGIN
          SELECT * FROM
          (
              SELECT
                  ROW_NUMBER() OVER(ORDER BY  
                  CASE WHEN @SortType = '1' THEN mt.Ad END ASC,
                  CASE WHEN @SortType = '2' THEN mt.Ad END DESC,
                  CASE WHEN @SortType = '3' THEN mt.Fiyat END ASC,
                  CASE WHEN @SortType = '4' THEN mt.Fiyat END DESC) AS RowNr, * 
              FROM @MainTable mt
              WHERE mt.Fiyat &gt; @MinPrice AND mt.Fiyat &lt; @MaxPrice
              AND mt.MarkaId IN (SELECT bf.Data FROM dbo.Split(@BrandFilter, ',') bf)
          ) Result
          WHERE RowNr &gt; ((@PageNr-1) * 10) AND RowNr &lt;= ((@PageNr) * 10)  
      END
  </code></pre>
  
  <p>This code is the difference,</p>
  
  <pre><code>AND mt.MarkaId IN (SELECT bf.Data FROM dbo.Split(@BrandFilter, ',') bf)
  </code></pre>
  
  <p>Thanks..</p>