有没有办法在使用 sp_prepare 时排除元数据列结果

Is there a way to exclude the the metadata columns result when using sp_prepare

有没有办法在调用 sp_prepare 时排除 returned 元数据列?

示例:

CREATE OR ALTER PROCEDURE Test
AS
-- Prepare query
DECLARE @P1 int;  
EXEC sp_prepare @P1 output,   
    N'@Param int',  
    N'SELECT 1 as int;';

-- Return handle for calling application
SELECT @P1;

-- Unprepare the query
EXEC sp_unprepare @P1;

GO

EXEC Test

以下将 return 两个结果集,第一个是元数据,第二个是所需的结果。有没有办法排除元数据结果?

避免将结果集返回给客户端的一种方法是使用 INSERT...EXEC 将结果集插入到 table 变量或临时 table:

CREATE OR ALTER PROCEDURE Test
AS
-- Prepare query
DECLARE @P1 int;  
DECLARE @trash TABLE(int int);
INSERT INTO @trash
    EXEC sp_prepare @P1 output,   
        N'@Param int',  
        N'SELECT 1 as int;';

-- Return handle for calling application
SELECT @P1;

-- Unprepare the query
EXEC sp_unprepare @P1;
GO