我已经学习了大约三个星期的SQL,现在我正在处理可编程对象,特别是用户定义的函数。我创建了这个UDF,并且在执行时,它只显示列名但不显示我想要的结果。我以为我控制了它,但即使它对我有意义也找不到我的错误。可能是逻辑错误还是语法错误?我的道歉,如果答案是显而易见的,我只是想不出来!
IF OBJECT_ID('dbo.ufn_ReturnLowestLineTotal') IS NOT NULL
DROP FUNCTION dbo.ufn_ReturnLowestLineTotal;
GO
CREATE FUNCTION dbo.ufn_ReturnLowestLineTotal
(
@SalesID INT
)
RETURNS INT
AS
BEGIN
DECLARE @Return INT
SELECT @Return = MIN(LineTotal)
FROM SalesLT.SalesOrderDetail
WHERE SalesOrderID = @SalesID
RETURN @Return
END
GO
--------- TEST RUN QUERY ----------------
SELECT SalesOrderID, LineTotal, ProductID
FROM SalesLT.SalesOrderDetail
WHERE LineTotal = dbo.ufn_ReturnLowestLineTotal(71815);