-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