如何将存储过程输出获取到 T-SQL 函数内的变量中?
我有一个任务,只能通过在运行时构建查询并使用 sp_executesql 执行它来完成。结果必须是一个布尔值(0/1 整数),我需要将其作为函数的结果返回。
我发现捕获 SP 输出的唯一方法是“INSERT INTO [table] EXECUTE [sp]”查询,但函数禁止这样做。
有什么想法如何克服这个问题?
I've got a task which can be only accomplished by construction a QUERY at runtime and executing it with sp_executesql. The result has to be a boolean (0/1 integer) value which I need to return as a result of the function.
The only way I found to capture an SP's output is "INSERT INTO [table] EXECUTE [sp]" query, but functions forbid this.
Any ideas how to overcome this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
sp_executesql 允许您传入参数,还可以将参数声明为用于输出。看一下这个简单的示例,它不是很动态,但显示了
sp_executesql
的输出参数如何工作sp_executesql allows you to pass in parameters, but also to declare parameters as being for output. Just have a look at this simple example that is not very dynamic, but shows how output parameters for
sp_executesql
work