하나의 행이 아닌 테이블에 대해 저장 프로 시저를 실행하려고합니다. 레코드를 테이블에 삽입하고 업데이트를해야하므로 저장 프로 시저를 선택합니다. 이 메서드는 걸려있는 것 같습니다. 설명 계획을 살펴 봤지만 내 논리가 잘못되어 한 레코드를 처리하고 중단합니다.테이블의 저장 프로 시저 실행
이것은 내가 지금까지 가지고있는 코드입니다. 내 저장 프로 시저가 짐승처럼 실행되고 나는 그것이 문제라고 생각하지 않는다.
---- Create a driver table for the stored procedure to run off .
drop table #Driver_Table
select col1, col2
IDENTITY(int) AS idcol
INTO #Driver_Table
FROM CUSTOMER
--- Contains about 37 k records
--- Index added for performance
CREATE CLUSTERED INDEX IDX_C_Driver_Table_UserID ON #Driver_Table(idcol)
-- Define the last customer ID to be handled
DECLARE @LastCustomerID INT
SET @LastCustomerID = 0
--- Other parameter the queries will use
DECLARE @idcol INT
DECLARE @col1 datetime
DECLARE @col2 varchar(200)
SET @idcol= 0
-- Iterate over all customers
BEGIN
-- Get next customerId
SELECT TOP 1 @idcol = idcol FROM #Driver_Table
WHERE idcol > @LastCustomerID
select TOP 1 @col1=col1
FROM #Driver_Table
WHERE idcol > @LastCustomerID
select TOP 1 @col2=col2
FROM #Driver_Table
WHERE idcol > @LastCustomerID
---- To get the process to end when last customer is processed.
WHILE @col2 NOT NULL
-- call your sproc
EXEC SP @col1,@Col2
-- set the last customer handled to the one we just handled
SET @LastCustomerID = @idcol
SET @col2 = NULL
-- select the next customer to handle
SELECT TOP 1 @col2 = col2
FROM #Driver_Table
WHERE idcol > @LastCustomerID
END
내가 거기에 볼 수 있습니다 제공된 정보를 사용하여 SQL Server 2005의
GO
당신 수 없습니다 "테이블에 대한 저장 프로 시저를 실행"-하지만 당신은 저장 프로 시저를 변경 (또는 새로 추가) 모든 반대로 세트를 처리하는 수 이 임시 테이블/커서 바쁜 작업. SP의 정의를 보여 준다면 누군가가 당신을 도울 수 있습니다. –