INSERT EXEC语句不能嵌套错误

时间:2014-09-08 16:58:34

标签: sql-server stored-procedures

我有两个存储过程,我将一个存储过程的结果集插入到sql server 2012中的表中。但是,我收到这两个错误,我不知道如何解决它们。     第一个错误:无法嵌套INSERT EXEC语句。     第二个错误:插入错误:列名或提供的值数与表定义不匹配。

Here is my stored procedure code,

USE [my_DB]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:      <Author,,Name>
-- Create date: <Create Date,,>
-- Description: <Description,,>
-- =============================================
ALTER PROCEDURE [dbo].[sp_1] 
@Week int = 1,
@Year int = 2014
AS
BEGIN
declare @current_week int
set @current_week = datepart (week, getdate()) 
while @Week <= @current_week
begin
truncate table [my_DB].[dbo].[tb_name]
insert into [my_DB].[dbo].[tb_name]
exec sp_2 @Week,@Year
select @Week as Week_Number,* from [my_DB].[dbo].[tb_name] (nolock)
set @Week = @Week + 1
end
END

Here is what I am trying to do when I am getting the errors.

insert into tb_name exec dbo.sp_1 @Week=1, @Year=2014

Any ideas would be helpful.

Thanks.

0 个答案:

没有答案