列无法绑定到联接中

时间:2018-02-06 05:51:40

标签: sql-server

我正在计算员工所留下的叶子以及本月工资的增加和扣除。 我被困在这一点,我正在加入这些表,但我收到错误,我无法绑定FROM子句中指定的表中的一列。

以下是我的问题,如果有人可以提供帮助,我们将不胜感激。

SELECT 
[EI].[FirstName]+' '+[EI].[LastName] [Employee], 
[Addition].[Amount] [AdditionAmount], [AdditionType].[FullName] [AdditionType],
[Deduction].[Amount] [DeductionAmount], [DeductionType].[FullName] [DeductionType],
MONTH([Leave].[ApprovedOn]) AS [Month], Count(*) AS [LeaveTaken]

FROM

[HRM].[tbl_EmployeeSalary] [Salary],
[HRM].[tbl_EmployeeInfo] [EI]

FULL JOIN [HRM].[tbl_EmployeeLeave] [Leave] ON [EI].[ID] = [Leave].[EmpCode]
FULL JOIN [HRM].[tbl_EmployeeSalaryAddition] [Addition] ON [Salary].[ID] = [Addition].[EmpSalaryCode]
FULL JOIN [HRM].[tbl_AdditionType] [AdditionType] ON [AdditionType].[ID] = [Addition].[AdditionTypeCode]
FULL JOIN [HRM].[tbl_EmployeeSalaryDeduction] [Deduction] ON [Salary].[ID] = [Deduction].[EmpSalaryCode]
FULL JOIN [HRM].[tbl_DeductionType] [DeductionType] ON [DeductionType].[ID] = [Deduction].[DeductionTypeCode]


WHERE
MONTH([Leave].[ApprovedOn]) = MONTH(GetDate())

GROUP BY 
[EI].[FirstName]+' '+[EI].[LastName], 
[Addition].[Amount], [AdditionType].[FullName],
[Deduction].[Amount] , [DeductionType].[FullName],
MONTH([Leave].[ApprovedOn])

我非常确定存在某种语法问题,例如我无法设置的顺序。我试着搜索这个问题,但在我的案例中无法解决。

1 个答案:

答案 0 :(得分:1)

我没有表结构,此查询仍将删除您的语法错误

SELECT 
[EI].[FirstName]+' '+[EI].[LastName] [Employee], 
[Addition].[Amount] [AdditionAmount], [AdditionType].[FullName] [AdditionType],
[Deduction].[Amount] [DeductionAmount], [DeductionType].[FullName] [DeductionType],
MONTH([Leave].[ApprovedOn]) AS [Month], Count(*) AS [LeaveTaken]
FROM
[HRM].[tbl_EmployeeInfo] [EI]
FULL JOIN [HRM].[tbl_EmployeeLeave] [Leave] 
ON [EI].[ID] = [Leave].[EmpCode],
[HRM].[tbl_EmployeeSalary] [Salary]
FULL JOIN [HRM].[tbl_EmployeeSalaryAddition] [Addition] 
ON [Salary].[ID] = [Addition].[EmpSalaryCode]
FULL JOIN [HRM].[tbl_AdditionType] [AdditionType] 
ON [AdditionType].[ID] = [Addition].[AdditionTypeCode]
FULL JOIN [HRM].[tbl_EmployeeSalaryDeduction] [Deduction] 
ON [Salary].[ID] = [Deduction].[EmpSalaryCode]
FULL JOIN [HRM].[tbl_DeductionType] [DeductionType] 
ON [DeductionType].[ID] = [Deduction].[DeductionTypeCode]
WHERE
MONTH([Leave].[ApprovedOn]) = MONTH(GetDate())
GROUP BY 
[EI].[FirstName]+' '+[EI].[LastName], 
[Addition].[Amount], [AdditionType].[FullName],
[Deduction].[Amount] , [DeductionType].[FullName],
MONTH([Leave].[ApprovedOn])