我的子查询返回一个值,因为它是一个 MIN()。为什么我在调用函数时会收到以下错误?感谢 MS SQL Server 2008
子查询返回超过 1 个值。当子查询跟随时,这是不允许的......
Create Function dbo.ufnMinSpeed (
@Track AS varchar(3),
@Distance AS INT,
@Surface AS nchar(10),
@MaxDate AS nchar (10)
) Returns Decimal(15,2) As
Begin
Declare @MinSpeed Decimal(15,2)
Return (
Select Min (tr.Finaltime) Over (
Partition By th.TrackCode, tr.Distance, tr.Surface
) AS MinSpeed
From
dbo.tblHeader th,
dbo.tblRaceData tr,
dbo.tblStarters ts
Where
th.TrackCode = @Track And
tr.Distance = @Distance And
tr.Surface = @Surface And
th.RaceDate < @MaxDate And
tr.TrackDateRaceNumber = ts.TrackDateRaceNumber And
th.TrackDateNumber = tr.TrackDateNumber
)
Return @MinSpeed
End