Domanda

I need help.... I am not good at SQL I get this error when I try to apply a JOIN:

[ Token line number = 1,Token line offset = 66,Token in error = JOIN ]

This is My SQL:

var query = "SELECT Team.TeamName, Fixtures.HomeTeam" +
                "FROM Team" +
                "LEFT JOIN Fixtures" +
                "ON Team.TeamId=Fixtures.HomeTeam" +
                "ORDER BY Team.TeamName";

Team Table Has PK: TeamId Fixture Table Has FK: HomeTeam I am using WebMatrix 2. Razor WebPages

È stato utile?

Soluzione

No spaces between line concatenations. Change every line to include space at the end.

var query = "SELECT Team.TeamName, Fixtures.HomeTeam " +
            "FROM Team " +
            "LEFT JOIN Fixtures " +
            "ON Team.TeamId=Fixtures.HomeTeam " +
            "ORDER BY Team.TeamName";

Altri suggerimenti

As pointed by Charles Brentana, you have missed the spaces in your SQL command.

Maybe a better solution is to you use a verbatim string literal, i.e. a string created with an @ character before the double-quote character, that can span multiple lines:

var query = @"SELECT Team.TeamName, Fixtures.HomeTeam
                FROM Team
                LEFT JOIN Fixtures
                ON Team.TeamId=Fixtures.HomeTeam
                ORDER BY Team.TeamName";

You need spaces between your strings.

I avoid this by putting the space as the first character, so it's really obvious when you forget to code it:

var query = "SELECT Team.TeamName, Fixtures.HomeTeam" +
            " FROM Team" +
            " LEFT JOIN Fixtures" +
            " ON Team.TeamId=Fixtures.HomeTeam" +
            " ORDER BY Team.TeamName";

If you consistently code this way you'll be able to spot any missing spaces instantly.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top