Read BOL topic "CREATE FUNCTION".
The only EXECUTE statement allowed inside of UDF is "EXECUTE statements calling an extended stored procedures".
"Statements not in this list are not allowed in the body of a function"
Sorry, you cannot have any dynamic SQL inside of a function.