title: SQL IF inside a Function
body: <pre><code>ALTER FUNCTION [dbo].[FSmapping] (
      @runID as bigInt,
      @TypMap as char(1)
      )
  
  RETURNS TABLE
  AS
  RETURN
  
  
  IF (@TypMap ='C')
  BEGIN
  SELECT b.[A/C],g.accountNumber, b.[Process], g.[endingBalanceLC], g.beginningBalanceLC
  FROM table1 g
  LEFT JOIN  table2  b ON b.[Acc2]=g.Account_Synt
  where RunID = @runID
  END
  </code></pre>
  <p>I am trying to implement a table function in SQL. Basically it should have 3 more <code>IF</code>s and the only thing that's going to switch is the table2, from table2-4 based on inputs C I R S. The error is the <code>IF</code> statement, I know that something is missing, I am having a hard time implementing some sort of a switch function with table as a return value. The Select works flawlessly without the IF syntax, it also says errors on the two variables inside the IF</p>
  <blockquote>
  <p>Must declare the scalar variable runID and TypMap</p>
  </blockquote>