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

时间:2023-01-06 19:11:00

While executing following query, it shows error, "Incorrect syntax near the keyword 'ON'."

在执行以下查询时,它显示错误,“关键字'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";

2 个解决方案

#1


4  

You need to put space after INNER JOIN

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

INNER JOIN"+ "Work_Submission

INNER JOIN“+”Work_Submission

Should be

INNER JOIN "+ "Work_Submission

Wherever you have used the INNER JOIN, you missed that space. So put it wherever you have used this.

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

Using such large inline query, I would suggest you to use Stored Procedure instead of inline query, that will help you write query with ease as well as readability along with less chance to have typo errors.

使用这样的大型内联查询,我建议您使用存储过程而不是内联查询,这将帮助您轻松编写查询以及可读性,同时减少输入错误的机会。

#2


0  

Try this

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

#1


4  

You need to put space after INNER JOIN

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

INNER JOIN"+ "Work_Submission

INNER JOIN“+”Work_Submission

Should be

INNER JOIN "+ "Work_Submission

Wherever you have used the INNER JOIN, you missed that space. So put it wherever you have used this.

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

Using such large inline query, I would suggest you to use Stored Procedure instead of inline query, that will help you write query with ease as well as readability along with less chance to have typo errors.

使用这样的大型内联查询,我建议您使用存储过程而不是内联查询,这将帮助您轻松编写查询以及可读性,同时减少输入错误的机会。

#2


0  

Try this

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