server sql 将存储过程执行的结果保存到表变量
declare @table table (
[SEQ] [INT] NOT NULL,
[MTIME] [DATETIME] NOT NULL,
[ISVALID] [NUMERIC](1, 0) NOT NULL ,
[P_SEQ] [INT] NOT NULL,
[ISS_TYPE] [INT] NOT NULL,
[SEQUENCE] [INT] NOT NULL,
[LOCK_OBJ_NAME] [VARCHAR](100) NULL,
[LOCK_OBJ_CODE] [INT] NULL,
[LOCK_CLS] [INT] NULL,
[LOCK_VOL] [NUMERIC](18, 4) NULL,
[LOCK_BEGIN] [DATETIME] NULL,
[LOCK_PERIOD] [NUMERIC](7, 2) NULL,
[LOCK_END] [DATETIME] NULL,
[LOCK_OBJ_CODE_MARK] [INT] NULL,
[ACT_END_DATE] [DATETIME] NULL,
[ACT_LOCK_VOL] [NUMERIC](18, 4) NULL,
[REMARK] [VARCHAR](400) NULL,
[IF_UNLTD] [INT] NULL,
[TOT_LOCK_VOL] [NUMERIC](18, 4) NULL,
[C_SEQ] [INT] NULL
)
insert into @table
exec tran_C_C..C_STK_LIST_RESULT_2_C_STK_ISS_DETAIL 4127
参考网址:https://blog.csdn.net/easyboot/article/details/78999591
定义一个存储过程如下:
@id int
as
select 1 as id, ' abc ' as name union all
select @id as id, ' bcd ' as name
返回两行数据.
现在想用SQL语句来调用这个存储过程,并把他返回的表放入变量中.可以如下做:
insert into @table exec test1 2 -- 将存储过程执行的结果放入表变量中
select *
from @table -- 查看表变量中的结果