3

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

Dawood Awan
  • 7,051
  • 10
  • 56
  • 119

3 Answers3

3

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";
Charles Bretana
  • 143,358
  • 22
  • 150
  • 216
1

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";
GmG
  • 1,372
  • 1
  • 9
  • 10
0

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.

Bohemian
  • 412,405
  • 93
  • 575
  • 722