2016-07-17 42 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を必要としません。