执行以下查询时,会显示错误,“关键字'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";
答案 0 :(得分:4)
您需要在INNER JOIN
INNER JOIN“+”Work_Submission
应该是
INNER JOIN "+ "Work_Submission
无论你使用INNER JOIN
,都错过了这个空间。所以把它放在你用过的地方。
使用如此大的内联查询,我建议您使用Stored Procedure
而不是内联查询,这将有助于您轻松编写查询以及可读性,同时减少输入错误的机会。
答案 1 :(得分: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";