SQL在FROM和INTERNAL JOIN之后和之前的表名附近的语法不正确。

SQL在FROM和INTERNAL JOIN之后和之前的表名附近的语法不正确。,sql,exception,Sql,Exception,嗨,我有这个选择查询。我尝试过在VisualStudio2008上的SQL窗格上执行查询,结果很好。但是,当我运行该页面(这是一个asp.net页面)时,它会抛出一个SQL异常,说我在计划附近有一个不正确的语法 string selectSchedString = "SELECT Subjects.subject_title, Schedules.class_day, CAST(MIN(Schedules.time_in) AS varchar(10)) + ' - ' + CAST(MAX(S

嗨,我有这个选择查询。我尝试过在VisualStudio2008上的SQL窗格上执行查询,结果很好。但是,当我运行该页面(这是一个asp.net页面)时,它会抛出一个SQL异常,说我在计划附近有一个不正确的语法

string selectSchedString = "SELECT Subjects.subject_title, Schedules.class_day, CAST(MIN(Schedules.time_in) AS varchar(10)) + ' - ' + CAST(MAX(Schedules.time_out) AS varchar(10)) AS Expr1" +
            "FROM Schedules "+ //The exception points here       
            "INNER JOIN Subjects ON Schedules.subject_id = Subjects.subject_id " +
            "INNER JOIN Student ON Student.section_id = " + currentSection + " " +
            "GROUP BY Subjects.subject_title, Schedules.class_day";

有什么想法吗?正如我所说的,我尝试在SQL窗格上执行此操作,结果成功了。asp.net中是否有我遗漏的特殊情况或其他情况?

您在第一行末尾和
中的
之间缺少任何空格


更改为Expr1“
作为Expr1”

第一行末尾和
中的
之间缺少任何空格


更改为Expr1“
作为Expr1”

这是因为指定的字符串不正确,请尝试:

string selectSchedString = "SELECT Subjects.subject_title, Schedules.class_day, CAST(MIN(Schedules.time_in) AS varchar(10)) + ' - ' + CAST(MAX(Schedules.time_out) AS varchar(10)) AS Expr1" +
            " FROM Schedules "+ //The exception points here       
            " INNER JOIN Subjects ON Schedules.subject_id = Subjects.subject_id " +
            " INNER JOIN Student ON Student.section_id = " + currentSection + " " +
            " GROUP BY Subjects.subject_title, Schedules.class_day";

请注意空格。

这是因为指定的字符串不正确。请尝试:

string selectSchedString = "SELECT Subjects.subject_title, Schedules.class_day, CAST(MIN(Schedules.time_in) AS varchar(10)) + ' - ' + CAST(MAX(Schedules.time_out) AS varchar(10)) AS Expr1" +
            " FROM Schedules "+ //The exception points here       
            " INNER JOIN Subjects ON Schedules.subject_id = Subjects.subject_id " +
            " INNER JOIN Student ON Student.section_id = " + currentSection + " " +
            " GROUP BY Subjects.subject_title, Schedules.class_day";

注意那些空白处。

哦,天哪。我花了最后一个小时重新键入单词时间表,放置空格,将其分配给不同的变量。谢谢!哈哈,有时候第二双眼睛可以更容易地发现这些东西。哦,天哪。我花了最后一个小时重新键入单词时间表,放置空格,将其分配给不同的变量。谢谢!哈哈,有时候第二双眼睛可以更容易地发现这些东西。