开发者

SQL incorrect syntax near a table name after FROM and before INNER JOIN.

开发者 https://www.devze.com 2023-04-01 14:33 出处:网络
Hi I have this SELECT query. I\'ve tried excuting the query on the SQL Pane on Visual Studio 2008 and it works. However when I run the page (this is an asp.net page), it throws an SQL Exception saying

Hi I have this SELECT query. I've tried excuting the query on the SQL Pane on Visual Studio 2008 and it works. However when I run the page (this is an asp.net page), it throws an SQL Exception saying I have an incorrect syntax near Schedules.

string selectSched开发者_如何学运维String = "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";

Any ideas? As I've said, I tried excuting this on the SQL pane and it worked. Is there any special condition in asp.net that I've missed or something?


You are missing any white space between the end of the first line and FROM

Change AS Expr1" to AS Expr1 "


This is because the concatinated string is not correct try:

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";

Notice the empty spaces.

0

精彩评论

暂无评论...
验证码 换一张
取 消