关键字“ON”附近的语法不正确

本文关键字:语法 不正确 ON 关键字 | 更新日期: 2023-09-27 18:33:58

执行以下查询时,它显示错误"关键字'ON'附近的语法不正确"。

string query = "SELECT Employee_Master.Employee_Code AS 'EmployeeCode',
       Employee_Master.Employee_ID AS'Employee_ID',
       Employee_Master.FIRST_NAME +' '+ ISNULL(Employee_Master.MIDDLE_NAME,'') +' ' +Employee_Master.LAST_NAME AS'emp_Name',
       Task_Master.Task_Code AS'Task_Code',
       Task_Master.Task_Name AS'Task_Name',
       Task_Completion_Status_Master.Task_Complition_Status_Name AS 'Task_status',
       Work_Submission_Master.Submission_Date AS'Submission_Date' " + "FROM Work_Submission_Detail INNER JOIN"+ "Work_Submission_Master ON Work_Submission_Detail.Work_Submission_ID = Work_Submission_Master.Work_Submission_ID INNER JOIN"+ "Task_Master ON dbo.Work_Submission_Detail.Task_ID = Task_Master.Task_ID INNER JOIN"+ "Task_Completion_Status_Master ON "+ "Work_Submission_Detail.Completion_Status = Task_Completion_Status_Master.Task_Complition_Status_ID INNER JOIN"+ "Employee_Master ON Work_Submission_Master.Employee_ID = Employee_Master.Employee_ID";

关键字“ON”附近的语法不正确

你需要在INNER JOIN之后放置空格

内联接"+"Work_Submission

应该是

INNER JOIN "+ "Work_Submission

无论你在哪里使用INNER JOIN,你都错过了那个空间。所以把它放在你用过这个的地方。

使用

如此大的内联查询,我建议您使用Stored Procedure而不是内联查询,这将帮助您轻松编写查询以及可读性,同时减少出现拼写错误的机会。

试试这个

string strqry = "SELECT EM.Employee_Code as 'EmployeeCode', EM.Employee_ID as'Employee_ID', EM.FIRST_NAME +' '+ ISNULL(EM.MIDDLE_NAME,'') +' ' +EM.LAST_NAME as'emp_Name', TM.Task_Code as'Task_Code', TM.Task_Name as'Task_Name',Task_Completion_Status_Master.Task_Complition_Status_Name as 'Task_status',WSM.Submission_Date as'Submission_Date' " +
"FROM Work_Submission_Detail WSD INNER JOIN "+
"Work_Submission_Master WSM ON WSD.Work_Submission_ID = WSM.Work_Submission_ID INNER JOIN "+
"Task_Master TM ON dbo.WSD.Task_ID = TM.Task_ID INNER JOIN "+
"Task_Completion_Status_Master ON "+
"WSD.Completion_Status = Task_Completion_Status_Master.Task_Complition_Status_ID INNER JOIN "+
"Employee_Master EM ON WSM.Employee_ID = EM.Employee_ID";