【发布时间】:2016-11-15 10:07:23
【问题描述】:
我有以临时表形式输出的存储过程
Create Proc Hello (@id int,@name nvarchar(30))
as
begin
If (OBJECT_ID('tempdb..#Welcome') Is Not Null) Drop Table #Welcome
select * into #Welcome from hello where id=@id
If (OBJECT_ID('tempdb..#Welcomes') Is Not Null) Drop Table #Welcomes
select * into #Welcomes from hello where name=@name
end
现在我得到了 2 个临时表作为我将在数据集中使用的结果..
现在我需要在另一个存储过程中访问这个#welcome ..我的意思是
Create Proc HelloThere(@ids int,@name nvarchar(10))
as
begin
exec hello @id = @ids ,@name =@name
//select * from #Welcome(Here i need to access the #Welcome so i can perform inner join something like below//
select * from #welcome inner join Atable on #welcome.id=Atable.id
end
【问题讨论】:
-
临时表是在过程之间共享数据的一种方式,但不是唯一的一种,也不是最好的一种。请参阅 here 以获取完整概述,包括您如何使用临时表。
-
感谢 Jereon 非常有帮助且内容丰富
标签: sql-server stored-procedures