将存储过程结果集放入表中 - 除了 INSERT INTO...EXEC 之外还有其他快捷方式吗?

发布于 2024-08-25 17:10:39 字数 285 浏览 4 评论 0原文

我正在创建一个临时表,它是存储过程结果集的结果。现在我正在使用create table语句,然后是insert into....exec

它完成了工作,但我很好奇是否还有其他方法可以解决这个问题?我希望可以运行 select into,让存储过程的结果集充当 select 语句的角色,这样我就不必事先编写 create 语句(这样如果存储过程的列发生变化,不需要任何修改。)

如果有其他方法可以更好地满足我的需求,我很乐意听到它们。非常感谢。

I'm creating a temp table that's the result of a stored procedure's result set. Right now I'm using the create table statement, followed by insert into....exec.

It gets the job done but I was curious if there are other ways of going about this? I wish it were possible to run a select into, with the stored procedure's result set serving the role of the select statement, so that I wouldn't have to write a create statement beforehand (so that if the stored proc's columns change, there wouldn't be any modifications needed.)

If there are other ways to go about this that might fit my needs better I'd love to hear about them. Thanks very much.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

一直在等你来 2024-09-01 17:10:39

有几种方法:表变量CTE。每个都有好处,您的场景往往让我相信,如果源数据很大,临时表是最佳选择。如果不是,我会倾向于 CTE。

There are a couple of ways: Table variables and CTEs. There are a benefits to each and your scenario tends to lead me to believe that a Temp Table is the best option if the source data is substantial. If it's not, I would lean towards a CTE.

热鲨 2024-09-01 17:10:39

一个技巧:

SELECT * FROM OPENQUERY(ThisServerName, 'EXEC myDB.dbo.myStoredproc') 

存储过程不是表或视图,因此您不能期望像表或视图那样的记录集。
您对“如果存储过程列发生变化”的评论忽略了这个事实:它不应该改变

One trick:

SELECT * FROM OPENQUERY(ThisServerName, 'EXEC myDB.dbo.myStoredproc') 

Stored procs are not tables or views so you can't expect a recordset like you would a table or view.
You comment about "if the stored proc columns change" is overlooking this fact: it shouldn't change

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文