将存储过程结果插入临时 table

Insert stored procedure results into temp table

我有一个存储过程 returns 这个结果:

我调用存储过程的方式是:

Exec uspGetStandardUsingRoleandPhase '1908003'

我想将这些结果存储到一个临时文件中 table 所以我使用 insert into 这样的:

IF OBJECT_ID(N'tempdb.dbo.#tmp', N'U') IS NOT NULL
    DROP TABLE #tmp

CREATE TABLE #tmp
(
    startDate DATE,
    endDate DATE,
    strPhase NVARCHAR(50),
    strBadgeNumber NVARCHAR(30)
)

INSERT INTO #tmp (startDate, endDate, strPhase, strBadgeNumber)
    EXEC uspGetStandardUsingRoleandPhase '1908003'

但是我得到这样的错误:

INSERT EXEC failed because the stored procedure altered the schema of the target table.

如果没有看到存储过程的代码就很难说,但我猜测该过程还会创建一个名为 #tmp 的临时文件 table。尝试创建一个具有不同名称的临时 table,然后 运行 将您的 INSERT EXEC 插入其中,或者 post 程序代码以便我们可以看到它。

值得注意的是,如果您使用的是查询存储,这也可能会在 SQL 2016 年出现,并且恰好 运行 在程序执行期间进行清理。他们建议增加查询存储大小以降低可能性,但除此之外,他们不打算在 SQL 2016 年修复它(已在 2017 年修复)

https://support.microsoft.com/en-us/help/4465511/error-556-insert-exec-failed-stored-procedure-altered-table-schema