为什么我从以下代码中得到错误“关键字'AS'附近的语法不正确?”
DECLARE @FirstHole INTEGER
SELECT MIN(HoleId) FROM dbo.Holes WHERE CourseId = (
SELECT MAX(dbo.Holes.CourseId) FROM dbo.Registration
LEFT JOIN dbo.Competitions ON dbo.Registration.CompetitionId = dbo.Competitions.CompetitionId
LEFT JOIN dbo.Holes ON dbo.Competitions.CourseId = dbo.Holes.CourseId WHERE RegistrationId = 102
) AND dbo.Holes.MarkerId = 2 AS @FirstHole
答案 0 :(得分:1)
这不是您在TSQL中分配给变量的方式。
我认为你打算这样做
DECLARE @FirstHole INTEGER
SELECT @FirstHole = MIN(HoleId) /* <-- Assignment here*/
FROM dbo.Holes
WHERE CourseId = (SELECT MAX(dbo.Holes.CourseId)
FROM dbo.Registration
LEFT JOIN dbo.Competitions
ON dbo.Registration.CompetitionId = dbo.Competitions.CompetitionId
LEFT JOIN dbo.Holes
ON dbo.Competitions.CourseId = dbo.Holes.CourseId
WHERE RegistrationId = 102)
AND dbo.Holes.MarkerId = 2