 <p>I need this too...</p> <p>The solution of Multi-Statement table-based function is good but not enough:</p> <pre><code>CREATE FUNCTION myProc (@ID Int) RETURNS @EmployeeList Table ( ID Int , Name nVarChar(50) , Salary Money ) AS BEGIN IF @ID IS NULL BEGIN INSERT INTO @EmployeeList (ID, Name, Salary) SELECT ID, Name, Salary FROM Employee END ELSE BEGIN INSERT INTO @EmployeeList (ID, Name, Salary) SELECT ID, Name, Salary FROM Employee WHERE ID = @ID END RETURN END GO </code></pre> <p>One must <em>d e f i n e</em> a return table so that a predefined field must be returned and not any table like</p> <pre><code>if @tableNum=1 then select * from tableA --(tableA and tableB are completely differnt ) else select * from tableB </code></pre>