2016-07-17 4 views
-1

SQL Server 함수가 아무런 값도 반환하지 않습니다. 아래는 내 스크립트입니다. 도와주세요. 미리 감사드립니다. SQL 함수가 어떤 값도 반환하지 않습니다.

CREATE FUNCTION [dbo].[PreviousService](@Order int) 
RETURNS @rtTable TABLE 
(
     OrderId Int, 
     PreviousService Int, 
     CurrentService Int 
) 
AS 
BEGIN 
Declare @PreviousService Int, 
     @CurrentService Int 

DECLARE @resultTbl table (OrderId Int,PreviousService Int,CurrentService Int) 

Select Top 2 @PreviousService=II.ServiceId 
     From InvoiceItems II 
     Inner Join Invoices I On I.Id = II.InvoiceId 
     Inner Join Orders O On II.OrderId=O.OrderId 
     where II.ServiceId is not null And O.OrderId= @Order And I.InvoiceStatus = 20 
     Order By I.CreateDate Desc 
Select Top 1 @CurrentService=II.ServiceId 
From InvoiceItems II 
Inner Join Invoices I On I.Id = II.InvoiceId 
Inner Join Orders O On II.OrderId=O.OrderId 
where II.ServiceId is not null And [email protected] And I.InvoiceStatus = 20 
Order By I.CreateDate Desc 

insert into @resultTbl 
Select O.OrderId,@CurrentService,@PreviousService 
From Orders O 
Where [email protected] 
return; 
END 

답변

0

당신은 당신이 @rtTable 직접

변화

insert into @rtTable 
Select O.OrderId,@CurrentService,@PreviousService 
From Orders O 
Where [email protected] 
마지막 INSERT 문에 삽입 할 수 있으며, @resultTbl을 요구하지 않는다
관련 문제