2012-11-15 6 views
1

저장 프로 시저의 결과를 사용하여 테이블을 업데이트해야하는 요구 사항이 있습니다.저장 프로 시저 실행 및 테이블 업데이트

예 :

Declare @result1 decimal 
Declare @price deciaml 

Create Table #OrderDetails 
{ 
    @orderID bigint 
    ,@orderName nvarchar(9) 
    ,@orderPrice decimal 
    ,@orderFlag nchar(1) 
} 

Insert into #OrderDetails 
{ 
    @orderID 
    ,@orderName 
    ,@orderPrice 
    ,@orderFlag 
} Select * from CartDetails 


Update #OrderDetails 
set @orderFlag = 1 
from #OrderDetails 
where orderID = 1 

--Now update each row of #OrderDetails by calling a stored procedure 
Update #OrderDetails 
set @orderPrice= @result1 
from (exec store_proc_calc_price orderID, orderName, @price = @result1 Output) 

#OrderDetails에서 각 행의 저장 프로 시저를 실행하고 저장 프로 시저의 결과에서 @orderPrice를 업데이트 할 수있는 방법이 있나요?

답변

0

예, 그렇게 할 수 있습니다. 커서를 만들어 테이블의 모든 행을 반복하고 각 행에 대해 저장 프로 시저를 호출해야합니다. 도움말에서 커서에 대한 예제를 보면 꽤 똑바로 앞으로 ...

+0

현재 구현에는 커서가 있으며 커서를 제거하려고 시도하고 있습니다. – user1825332

+0

커서에 어떤 문제가 있습니까? 테이블의 모든 라인에 대해 sp를 호출하는 다른 방법은 없습니다 ... –