Why can we not execute a stored procedure inside a function in SQL Server

前端 未结 7 1533
情话喂你
情话喂你 2020-12-17 02:23

Why can we not execute a stored procedure inside a function when the opposite is possible?

7条回答
  •  猫巷女王i
    2020-12-17 02:55

    You would need to change your stored procedure to a Function to call it from within a Function.

    Or, 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.

    eg.

    Create Function...
    
    EXEC master.sys.xp_cmdshell 'C:\test.bat'
    
    RETURN...
    

    I am in no way saying that this is good practice but am just saying it's a possibility.

提交回复
热议问题