从函数执行存储过程 [英] Execute Stored Procedure from a Function

查看:30
本文介绍了从函数执行存储过程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道这已经被要求死了,我知道为什么 SQL Server 不允许你这样做.

I know this has been asked to death, and I know why SQL Server doesn't let you do it.

但是除了使用扩展存储过程之外,还有其他解决方法吗?

But is there any workaround for this, other than using Extended Stored Procedures?

并且请不要告诉我将我的函数转换为过程...

And please don't tell me to convert my function into a procedure...

所以我真正要问的是:有没有办法在函数内运行存储过程?

So what I'm really asking is: Is there ANY way to run a Stored Procedure from within a Function?

事实证明:有办法解决它,但它错误我不会这样做.我要将其更改为存储过程并在其他地方执行.

Point proven: there is a way around it, but it's so WRONG I wouldn't do it. I'm gonna change it to a Stored Procedure and execute it elsewhere.

推荐答案

我没有试过这个,所以我不能保证!你已经知道你不应该这样做,所以请不要这样做.但是...

I haven't tried this, so I can't vouch for it! And you already know you shouldn't be doing this, so please don't do it. BUT...

试试看这里:http://sqlblog.com/博客/denis_gobo/archive/2008/05/08/6703.aspx

关键是我为了你的目的试图调整的这一点:

The key bit is this bit which I have attempted to tweak for your purposes:

DECLARE @SQL varchar(500)

SELECT @SQL = 'osql -S' +@@servername +' -E -q "exec dbName..sprocName "'

EXEC master..xp_cmdshell @SQL

这篇关于从函数执行存储过程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆