具有多个表的SQL别名

时间:2015-02-11 15:34:23

标签: sql sql-server tsql alias

我希望从Report,Player和Fixture表中选择所有字段,其中Report表中的FixtureID与@FixtureID(从组合框中选择)匹配。但是,我无法使别名正常工作 - 我尝试使用与Report和Fixture相同的方式对Player表进行别名,但这也会引发错误。

               SELECT 
                    r.*,
                    Player.*,
                    f.*,
                    isNull(Player.PlayerFirstName + ' ' + Player.PlayerLastName, ' ') AS 'PlayerName' 
                FROM 
                    Report AS r, Fixture AS f
                INNER JOIN Player ON Player.PlayerID = r.PlayerID
                INNER JOIN f ON f.FixtureID = r.FixtureID
                WHERE
                    r.FixtureID = @FixtureID
                ORDER BY 
                    ReportDate

错误说明:"多部分标识符" r.PlayerID"不能被约束"。

任何建议都将不胜感激。

1 个答案:

答案 0 :(得分:3)

试试这个......

SELECT r.*
    ,Player.*
    ,f.*
    ,isNull(Player.PlayerFirstName + ' ' + Player.PlayerLastName, ' ') AS 'PlayerName'
FROM Report AS r
INNER JOIN Player ON Player.PlayerID = r.PlayerID
INNER JOIN Fixture AS f ON f.FixtureID = r.FixtureID
WHERE r.FixtureID = @FixtureID
ORDER BY ReportDate