选择存储过程返回的列
我有一个存储过程,它返回大约 50 列。我想编写一个查询,在其中我将能够从 SP 返回的列列表中选择特定列。
我尝试编写 select RSA_ID from exec(uspRisksEditSelect '1')
但它抛出了一个错误。 我认为我们需要为其编写一些动态sql。但我对此很陌生。
I have a stored procedure which is returning me about 50 columns. I want to write a query, where I will be able to select a particular column from the list of column returned by the SP.
I tried writing select RSA_ID from exec(uspRisksEditSelect '1')
But Its throwing me an error.
I think we need to write some dynamic sql for it. But I am new to it.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您不能直接使用存储过程的结果 - 您需要将其存储到内存中或临时表中并从那里开始:
但是绝对没有必要使用动态 SQL......
You cannot use the results of a stored proc directly - you need to store that into an in-memory or temporary table and go from there:
But there's definitely no need to use dynamic SQL.....
您应该编写一个表值用户函数。
You should write a table-valued user function.
如果您能够修改存储过程,则可以轻松地将所需列数作为参数:
在这种情况下,您不需要手动创建临时表 - 它会自动创建。希望这有帮助。
If you are able to modify your stored procedure, you can easily put number of needed columns as parameter:
In this case you don't need to create temp table manually - it creates automatically. Hope this helps.