是否可以在存储过程中调用存储过程并将结果放入#temp 表中,而无需先创建临时表?

发布于 2024-12-27 09:52:57 字数 492 浏览 1 评论 0原文

我试图从另一个存储过程中调用一个存储过程,并将结果放入临时表中,而不先创建临时表。是否可以这样做,或者有更好的方法吗?我想使用结果集具有多列和多行的 sprocB 或 functionB。谢谢。

sproc A  
..
begin
  -- create table #tmp.... -- Try not to create the #tmp table first if possible
  exec sproc_B ... put results from sproc_B in #tmp

end

sproc B
..
@id int
..
begin
  select table from aTable where id = @id
end

此处提出了类似的问题。

I'm trying to call a sproc from within another sproc and putting the results in a temp table without first creating the temp table. Is it possible to do this, or is there a better way? I want to use the sprocB or functionB whose result set has multiple columns and multiple rows. thx.

sproc A  
..
begin
  -- create table #tmp.... -- Try not to create the #tmp table first if possible
  exec sproc_B ... put results from sproc_B in #tmp

end

sproc B
..
@id int
..
begin
  select table from aTable where id = @id
end

Similiar question was asked here.

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

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

发布评论

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

评论(3

幸福%小乖 2025-01-03 09:52:57
  create table #tmp....

  insert  #tmp
  exec sproc_B
  create table #tmp....

  insert  #tmp
  exec sproc_B
静谧 2025-01-03 09:52:57
CREATE TABLE #tmpTable
(
   COL1 INT,
   COL2 INT   
)

INSERT INTO #tmpTable 
Exec spGetResultset 'Params'
CREATE TABLE #tmpTable
(
   COL1 INT,
   COL2 INT   
)

INSERT INTO #tmpTable 
Exec spGetResultset 'Params'
你与清晨阳光 2025-01-03 09:52:57

是的,但是您必须在使用 in 之前创建表。语法是:

INSERT INTO YourTable EXEC YourProc

不用说,表的结构应该与 SP 的输出匹配?

Yes, but you have to create table prior to using in. The syntax is:

INSERT INTO YourTable EXEC YourProc

No need to say, that structure of the table should match the SP's output?

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