1

为什么我从以下代码中收到错误“关键字 '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
4

1 回答 1

1

That is not how you assign to a variable in TSQL.

I presume your intention is to do this

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 
于 2013-01-20T21:24:12.223 回答