sqlServer 执行存储过程结果存表中

--获取rowIndex  和 objectId

select rowindex,objectid, 0 as number into #tempObjectid from tempUser

--创建临时表,设置id为自增长,步长为1

CREATE TABLE [dbo].[#Temp123](
[id] [bigint] IDENTITY(1,1) NOT FOR REPLICATION NOT NULL,
[numbers] [float] NOT NULL
)

--定义变量

declare @id int ;
declare @num float ;
declare @totalNumber int;
declare @objectid nvarchar(100);

--设置初始值和最大值

set @id=1;
select @totalNumber=COUNT(*)+1 from #tempObjectid

--循环执行并插入到临时表

while(@id<@totalNumber)
begin
select @objectid=objectid from #tempObjectid where rowindex=@id
INSERT [#Temp123] exec Pro_Calculate(替换成要执行的存储过程)  @objectid,'2020'
set @id=@id+1;
end

--最终结果

select * from #tempObjectid as a
left join #Temp123 as b on a.rowindex=b.id

原文地址:https://www.cnblogs.com/chengzi00/p/14232715.html