我正在获得Msg 512,Level 16,State 1,Line 1

时间:2015-08-12 12:21:34

标签: sql sql-server

我在SQL中获得了msg 512。我正在尝试的是显示I_HR_EMPLOYEE_MASTER的员工姓名。

[Description("xxx")]

2 个答案:

答案 0 :(得分:0)

尝试此查询

     SELECT  A.MONTH,(  SELECT SUM(AMOUNT) 
                    FROM V_HR_PP_PROCESS_DATA 
                    WHERE EMPLOYER_CODE = A.EMPLOYER_CODE AND TAX_YEAR = A.TAX_YEAR AND 
                            PROCESS_MONTH = A.MONTH AND EMPLOYEE_ID IN 
                                (SELECT EMPLOYEE_ID 
                                 FROM I_HR_EMP_EMPLOYMENT_DTL 
                                WHERE EMPLOYER_CODE = A.EMPLOYER_CODE AND CONTRACT_TERM = 'P') AND 
                                    PROCESS_MONTH BETWEEN 1 AND 10 AND PD_CODE = 'Z500') AS GROSS_PERMANENT,
                                 b.EMPLOYEE_NAME    as employeename,                                
                                (SELECT SUM(AMOUNT) FROM V_HR_PP_PROCESS_DATA WHERE EMPLOYER_CODE = A.EMPLOYER_CODE 
                            AND TAX_YEAR = A.TAX_YEAR AND PROCESS_MONTH = A.MONTH AND EMPLOYEE_ID IN
                            (SELECT EMPLOYEE_ID FROM I_HR_EMP_EMPLOYMENT_DTL WHERE EMPLOYER_CODE = A.EMPLOYER_CODE 
                                    AND CONTRACT_TERM = 'F') AND PROCESS_MONTH BETWEEN  1 AND 10 AND PD_CODE = 'Z500') 
                                        AS GROSS_CASUAL  
FROM I_HR_SYS_DATE_MONTHLY A 
JOIN I_HR_EMPLOYEE_MASTER b on b.EMPLOYER_CODE=A.EMPLOYER_CODE  

在哪里A.EMPLOYER_CODE =' RAD' AND A.TAX_YEAR = 2014

答案 1 :(得分:0)

假设您的主表中有列员工ID,以便您可以将其与员工主人员一起加入。

**但我真的怀疑你将从这个查询中获得什么。 **

SELECT  A.MONTH,
(

  SELECT SUM(AMOUNT) FROM V_HR_PP_PROCESS_DATA WHERE EMPLOYER_CODE = A.EMPLOYER_CODE AND TAX_YEAR = A.TAX_YEAR AND 
  PROCESS_MONTH = A.MONTH AND EMPLOYEE_ID IN (SELECT EMPLOYEE_ID FROM I_HR_EMP_EMPLOYMENT_DTL WHERE EMPLOYER_CODE = A.EMPLOYER_CODE AND CONTRACT_TERM = 'P') AND 
  PROCESS_MONTH BETWEEN 1 AND 10 AND PD_CODE = 'Z500'
) AS GROSS_PERMANENT,
--(SELECT EMPLOYEE_NAME FROM I_HR_EMPLOYEE_MASTER),
B.EMPLOYEE_NAME, 
(
  SELECT SUM(AMOUNT) FROM V_HR_PP_PROCESS_DATA WHERE EMPLOYER_CODE = A.EMPLOYER_CODE 
  AND TAX_YEAR = A.TAX_YEAR AND PROCESS_MONTH = A.MONTH AND EMPLOYEE_ID IN
  (SELECT EMPLOYEE_ID FROM I_HR_EMP_EMPLOYMENT_DTL WHERE EMPLOYER_CODE = A.EMPLOYER_CODE 
  AND CONTRACT_TERM = 'F') AND PROCESS_MONTH BETWEEN  1 AND 10 AND PD_CODE = 'Z500'
) AS GROSS_CASUAL  
FROM I_HR_SYS_DATE_MONTHLY A 
left outer join I_HR_EMPLOYEE_MASTER B on A.EMPLOYEE_ID = B.EMPLOYEE_ID
WHERE A.EMPLOYER_CODE = 'RAD' AND A.TAX_YEAR = 2014