插入到一个临时表从SQL Server 2000上的存储过程(Insert into a temp

2019-09-17 18:36发布

我试图完成什么是说明如下:

http://sqldev.wordpress.com/2008/05/06/insert-into-temporary-table-from-stored-procedure/

文章说,(通过评论的支持),这适用于SQL服务器2000,但可能不那么容易。

这是一个有点棘手前2008年 - 因为它在SQL Server 2008原来这可以轻松完成。

并评论说:

这不是2008年的特点。 它在那里,因为我记得......从SQL Server 2000? 这是一个很大的特点呢!

我怎样才能快速完成这个对SQL Server 2000?

利用本文是基于,我收到以下错误消息的代码:

Msg 197, Level 15, State 1, Line 7
EXECUTE cannot be used as a source when inserting into a table variable.

我的确发现这个职位#1 ,它也支持,这可以在SQL Server 2000来完成这个概念,但这个职位是解决SQL Server 2005和它不进去2000多。

Answer 1:

您可以在SQL Server 2005版本起做到这一点。 尽管SQL Server 2000支持表变量,它不支持INSERTEXECUTE到表变量。 最接近的支持另一种方法是使用一个临时表。

而不是使用像表变量的@mytable ,使用一个名为像表#mytable ,你可以insert使用exec存储过程。 你需要先创建临时表使用create table命令。



Answer 2:

尝试使用真正的临时表,而不是表varaible ...

CREATE TABLE #jobs
( jobcount int
)
INSERT
INTO #jobs
EXEC
sp_executesql
N’select 1 AS jobcount’
SELECT
*
FROM #jobs


文章来源: Insert into a temp table from a stored procedure on Sql Server 2000