You can't do this. To be able to query different tables and columns, you need to use dynamic code. Dynamic code can be dangerous if it's not handled correctly and it's not allowed in functions.
By the way, you should try to use inline table valued functions to avoid performance problems.