我需要帮助....我不擅长SQL当我尝试应用JOIN时出现此错误:
[ Token line number = 1,Token line offset = 66,Token in error = JOIN ]
这是我的SQL:
var query = "SELECT Team.TeamName, Fixtures.HomeTeam" +
"FROM Team" +
"LEFT JOIN Fixtures" +
"ON Team.TeamId=Fixtures.HomeTeam" +
"ORDER BY Team.TeamName";
团队表有PK:TeamId 夹具表有FK:HomeTeam 我正在使用WebMatrix 2. Razor WebPages
答案 0 :(得分:3)
行连接之间没有空格。更改每一行以包含最后的空格。
var query = "SELECT Team.TeamName, Fixtures.HomeTeam " +
"FROM Team " +
"LEFT JOIN Fixtures " +
"ON Team.TeamId=Fixtures.HomeTeam " +
"ORDER BY Team.TeamName";
答案 1 :(得分:1)
正如Charles Brentana指出的那样,你错过了SQL命令中的空格。
也许更好的解决方案是使用逐字字符串文字,即在双引号字符之前用@字符创建的字符串,可以跨越多行:
var query = @"SELECT Team.TeamName, Fixtures.HomeTeam
FROM Team
LEFT JOIN Fixtures
ON Team.TeamId=Fixtures.HomeTeam
ORDER BY Team.TeamName";
答案 2 :(得分:0)
你的字符串之间需要空格。
我通过将空格作为第一个字符来避免这种情况,所以当您忘记编码时,这一点非常明显:
var query = "SELECT Team.TeamName, Fixtures.HomeTeam" +
" FROM Team" +
" LEFT JOIN Fixtures" +
" ON Team.TeamId=Fixtures.HomeTeam" +
" ORDER BY Team.TeamName";
如果您始终以这种方式编码,您将能够立即发现任何丢失的空间。