-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