Functions cannot "touch" any database but read them only. Stored procedures can do anything and everything with databases.
You cannot execute a stored procedure from a function. You can execute an extended stored procedure from a function.
There are several restrictions on what User Defined Functions (UDF's) can do.
Primarily, they cannot have code that has side effects.
Like, for example, they cannot make changes to tables (except to table variables defined in the function.
These restrictions allow better optimization of function calls.
But since those restrictions do not apply to stored procedures,
functions cannot call stored procedure's because there would be no efficient way of enforcing the "no side effects allowed"
rule if functions could call stored procedures.
one way is to use xp_cmdshell to call a batch file where the batch file contains the execute procedure statement.
In the function you can call the extended proc.
e.g.
You cannot execute a stored procedure from a function. You can execute an extended stored procedure from a function.
There are several restrictions on what User Defined Functions (UDF's) can do.
Primarily, they cannot have code that has side effects.
Like, for example, they cannot make changes to tables (except to table variables defined in the function.
These restrictions allow better optimization of function calls.
But since those restrictions do not apply to stored procedures,
functions cannot call stored procedure's because there would be no efficient way of enforcing the "no side effects allowed"
rule if functions could call stored procedures.
one way is to use xp_cmdshell to call a batch file where the batch file contains the execute procedure statement.
In the function you can call the extended proc.
e.g.
Create Function...
EXEC master.sys.xp_cmdshell 'C:\test.bat'
RETURN...