You can't, generally, parameterise the rowset sources in a FROM
clause. You could do the following and hope the optimizer is smart enough to do it right:
SELECT e.a,e.b,e.c,e.d,......
FROM (
SELECT * FROM dbo.fnFullTeamUnderManager(@manager_employee_number) WHERE @IsGetFullTeamUnderManager=1
UNION ALL
SELECT * FROM Employee WHERE @IsGetFullTeamUnderManager=0
) emp
INNER JOIN .....
WHERE ..........
If the function and Employee
don't share exactly the same columns, you'll have to name the common columns explicitly instead of using SELECT *
- some might insist that you should do that anyway, but today I'm in a "get it done" mood.