我有一个存储过程,见下文,执行。在存储过程中是exec命令。当我执行存储过程时,我得到两个结果集,我的exec命令的结果,然后是返回值。如何从exec命令中获得结果?
DECLARE @openquery NVARCHAR(MAX)
DECLARE @tsql NVARCHAR(MAX)
DECLARE @linkedserver NVARCHAR(10)
SET @linkedserver = 'orad'
SET @openquery = 'SELECT * FROM OPENQUERY(' + @linkedserver + ','''
SET @tsql = 'SELECT
COUNT(empl_id) AS emplcnt
FROM
(
SELECT
empl_id,
empl_last_nm,
empl_first_nm,
empl_middle_init,
empl_pay_plan_cd,
empl_stat,
empl_typ,
empl_cctr_id,
empl_corporate_id,
empl_dir_chrg_ind,
LEVEL
FROM
cdas.vdwhemp3
WHERE
empl_stat in (''''ACTIVE '''',''''DISABLED '''',''''LEAVE '''',''''MILITARY '''',''''SALARY CON'''',''''UNKNOWN '''')
START WITH
empl_id = '''''+ @id + '''''
CONNECT BY PRIOR
empl_id = empl_empl_id
ORDER SIBLINGS BY
empl_last_nm
)'')'
EXEC (@openquery+@tsql)