尝试执行我的 SQL Server 存储过程时出现此错误:当前命令发生严重错误。结果,如果有的话,应该丢弃。
这是打破的部分。任何想法为什么?谢谢!
IF @Supervisor = 1
AND @Calc = 1
BEGIN
INSERT INTO @Employees
SELECT [Employee_No]
FROM
dbo.fx_DetermineEmployeesBase
(
@Employee_ID
, NULL
, @Employee_ID
, 2
)
;WITH Applications AS
(
SELECT TOP 25
ROW_NUMBER() OVER (ORDER BY vw.[Fullname] ASC, vw.[Submission_Date] DESC) AS [Row]
, ((ROW_NUMBER() OVER (ORDER BY vw.[Fullname] ASC, vw.[Submission_Date] DESC) - 1) / @Page_Size) + 1 AS [Page_Number]
, vw.[Employee_No]
, CASE
WHEN fx.[New_Balance] > vw.[Balance] THEN vw.[Balance]
ELSE fx.[New_Balance]
END AS [Predicted_Balance]
FROM vw_Employee_Leave_Application vw
FULL OUTER JOIN @Employees e ON
vw.[Employee_No] = e.[Employee_No]
--This causes the error:
--A severe error occurred on the current command. The results, if any, should be discarded.
CROSS APPLY dbo.fx_Employee_Leave_Type_Balance_Predict_LastRow
(
NULL
, COALESCE
(
CASE
WHEN vw.[Start_Date] <=
(
SELECT TOP 1 [End_Date]
FROM vw_Employee_Leave_Planner
WHERE
[Employee_No] = vw.[Employee_No]
AND [Leave_Type_No] = vw.[Leave_Type_No]
AND
[Accepted] = 1
AND [End_Date] > GETDATE()
ORDER BY [End_Date] DESC
)
THEN
(
SELECT TOP 1 [End_Date]
FROM vw_Employee_Leave_Planner
WHERE
[Employee_No] = vw.[Employee_No]
AND [Leave_Type_No] = vw.[Leave_Type_No]
AND [Accepted] = 1
AND [End_Date] > GETDATE()
ORDER BY [End_Date] DESC
)
ELSE vw.[Start_Date]
END
, GETDATE()
)
, vw.[Employee_No]
, vw.[Leave_Type_No]
) fx
WHERE
(
vw.[Employee_No] = e.[Employee_No]
AND vw.Approver_No IS NULL
)
OR vw.[Approver_No] = @Approver_ID
),
PageSettings AS
(
SELECT TOP 1
[Row] AS [Item_Count]
, [Page_Number] AS [Page_Count]
FROM Applications
ORDER BY [Row] DESC
)
SELECT
[Row] AS [Row_Number]
, [Page_Number]
, @Page_Size AS [Page_Size]
, [Item_Count]
, [Page_Count]
FROM Applications, PageSettings
WHERE
[Page_Number] = @Page_No
OR @Page_No IS NULL
END