title: How can I use IF statement in SQL Server in order to show or hide some specific columns
body: <p>Suppose I have a table like : </p>
  
  <p>(<em>0 means in cash and any other value indicates <code>check serial number</code></em>)</p>
  
  <pre><code>ID    NAME     PaymentMethod       Amount          Bank
  ------------------------------------------------------------
  1     Alex          0               20             ''
  2     Sara       123456789         5000      Bank of America
  3     Mina          0               15             ''
  4     Scott      987456321        10000         Citibank
  </code></pre>
  
  <p>How can I use an <code>IF</code> statement so that if the <code>PaymentMethod</code> column contains <code>0</code> I hide this column and instead show a column with value of <code>Incash</code> and hide the bank column as well.  </p>
  
  <p>And when the <code>PaymentMethod</code> is anything else I just rename the column header to <code>CheckSerial</code>.</p>
  
  <p>To make it more clear I want the table to look like this; for those who have paid <code>InCash</code>, it shows up as: </p>
  
  <pre><code>ID    NAME       PaymentMethod       Amount  
  -------------------------------------------
  1     Alex          InCash            20  
  3     Mina          InCash            15        
  </code></pre>
  
  <p>for those how have paid by checks, it shows up as :  </p>
  
  <pre><code>ID    NAME   PaymentMethod  Serial Number     Amount          Bank
  -------------------------------------------------------------------
  2     Sara      Check        123456789        5000      Bank of America
  4     Scott     Check        987456321        10000         Citibank
  </code></pre>
  
  <p>I tried something like this , based on the given IDs,only one select statement executes:</p>
  
  <pre><code>    ALTER FUNCTION dbo.Function1(@IDTag bigint)
      RETURNS TABLE
      AS 
      if PaymentMethod = 0
      BEGIN  
      RETURN SELECT         ID, Name , PaymentMethod = InCash , Amount 
             FROM            tblTest
             WHERE        (ID = @IDTag)
             END
      ELSE 
             BEGIN 
             RETURN   SELECT        ID, Name , PaymentMethod ='By Check', PaymentMethod As [Serial number], Amount, Bank 
             FROM            tblTest
             WHERE        (ID = @IDTag)
  
             END
  </code></pre>
  
  <p>Is this even correct? 
  If this is not feasible or logical what better way can you suggest on this?</p>