【发布时间】:2017-11-07 06:55:52
【问题描述】:
我在 ForEach 循环容器中的 SSIS 中执行 SQL 任务中使用了 2 个存储过程。从第一个过程中,我将值作为 scope_identity 返回,我想在第二个存储过程中动态访问它。下面是存储过程。第一个存储过程:-
ALTER PROCEDURE [dbo].[insertTm]
@filename nvarchar(128),
@date date,
@count int,
@fileid int output
AS
BEGIN
INSERT INTO TmRecruitment(FileName,FileLoadDate,RecordCount)
VALUES (@filename, @date, @count)
SET @fileid=SCOPE_IDENTITY()
RETURN @fileid
END
I have created appropriate variables and mapped 3 variables as input and 1 variable as output variable to recieve the value of scope identity.
Second stored procedure is :-
ALTER proc [dbo].[toinsertTx]
(@fileido int)
as
begin
insert into TxRecruitment
(JobReqID,TemplateName,JobType,JobLevel,JobTitle,HeadcountType,Backfill,RequisitionStatus,Status,CurrentApprover,Department,SubDepartment
,CostCenterID,Country,JobPostingLocation,DepartmentHead,SubDeptHead,HiringManager,BudgetController,Recruiter,DateCreated,ApprovedDate
,Age,TimeToReqApproval,NoOfDaysOpen)
select * from TsRecruitment
update TxRecruitment set FileId=@fileido
end
我得到正确的所有事情,我将范围标识的值放入变量@fileido。我有 3 个文件,我希望范围标识在每次获取一个文件时返回 FileId 的值。但我得到的返回值只有一个为 3。但我希望值返回为 1,然后是 2,然后是 3。 正确的方法应该是什么,以便我每次都获得不同的返回值。
【问题讨论】:
标签: sql-server stored-procedures ssis