title: Problem with if-statement used at Table-returned-function in SQL
body: <p>I have simplified my function to the following:</p>
  
  <pre><code>create function [dbo].[UserSuperTeams](@ProjectId int) 
  returns table 
  as 
  return 
     if @ProjectId=0
     begin 
        select TeamId from TblTeam t 
          union
        select 0 as TeamId
     end
     else
     begin
        select t.TeamId from TblTeam t
          union
        select 1 as TeamId
     end;
  go
  </code></pre>
  
  <p>I cannot make it work.. It seems I have some syntax errors, but I cannot figure out how to make it work.. Any idea? </p>