-4

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

2 回答 2

4

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

INNER JOIN"+ "Work_Submission

应该

INNER JOIN "+ "Work_Submission

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

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

于 2013-10-04T11:21:26.713 回答
0

尝试这个

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";
于 2013-10-04T11:24:49.343 回答