2014-01-27 57 views
7

我有一個查詢,我試圖從MS SQL Server 2008轉換爲MySQL。它在MSSQL上運行正常, 我得到錯誤 「Incorrect parameter count in the call to native function 'ISNULL'」。調用本地函數'ISNULL'時的錯誤參數計數

我該如何解決這個問題?

SELECT DISTINCT 
    dbo.`@EIM_PROCESS_DATA`.U_Tax_year, 
    dbo.`@EIM_PROCESS_DATA`.U_Employee_ID, 
    CASE 
     WHEN dbo.`@EIM_PROCESS_DATA`.U_PD_code = 'SYS033' THEN SUM(dbo.`@EIM_PROCESS_DATA`.U_Amount) 
    END AS PAYE, 
    CASE 
     WHEN dbo.`@EIM_PROCESS_DATA`.U_PD_code = 'SYS014' THEN SUM(dbo.`@EIM_PROCESS_DATA`.U_Amount) 
    END AS TOTALTAXABLE, 
    dbo.OADM.CompnyName, 
    dbo.OADM.CompnyAddr, 
    dbo.OADM.TaxIdNum, 
    dbo.OHEM.lastName + ', ' + ISNULL(dbo.OHEM.middleName, '') + '' + ISNULL(dbo.OHEM.firstName, '') AS EmployeeName 
FROM 
    dbo.`@EIM_PROCESS_DATA` 
     INNER JOIN 
    dbo.OHEM ON dbo.`@EIM_PROCESS_DATA`.U_Employee_ID = dbo.OHEM.empID 
     CROSS JOIN 
    dbo.OADM 
GROUP BY dbo.`@EIM_PROCESS_DATA`.U_Tax_year , dbo.`@EIM_PROCESS_DATA`.U_Employee_ID , dbo.OADM.CompnyName , dbo.OADM.CompnyAddr , dbo.OADM.TaxIdNum , dbo.OHEM.lastName , dbo.OHEM.firstName , dbo.OHEM.middleName , dbo.`@EIM_PROCESS_DATA`.U_PD_code 

的MySQL

SELECT DISTINCT 
    processdata.taxYear, processdata.empID, 
    CASE WHEN processdata.edCode = 'SYS033' THEN SUM (processdata.amount) END AS PAYE, 
    CASE WHEN processdata.edCode = 'SYS014' THEN SUM (processdata.amount) END AS TOTALTAXABLE, 
    company.companyName, company.streetAddress, company.companyPIN, employeemaster.lastName + ', ' + IFNULL(employeemaster.middleName, '') 
    + ' ' + IFNULL(employeemaster.firstName, '') AS EmployeeName 
FROM   
    processdata INNER JOIN 
    employeemaster ON processdata.empID = employeemaster.empID 
    CROSS JOIN company 
    GROUP BY processdata.taxYear, processdata.empID, company.companyName, company.streetAddress, company.companyPIN, 
    employeemaster.lastName, employeemaster.firstName, employeemaster.middleName, processdata.edCode 
+0

您的MySQL查詢在哪裏? –

回答

1

我建議你切換到ANSI標準功能coalesce()

(dbo.OHEM.lastName + ', ' + coalesce(dbo.OHEM.middleName, '') + '' + coalesce(dbo.OHEM.firstName, '') 
) AS EmployeeName 

您還可以通過包含表別名來使您的查詢更易於閱讀。

編輯:

作爲一個說明,我似乎已經錯過了轉換的方向。 MySQL查詢將使用concat()

CONCAT(OHEM.lastName, ', ', coalesce(OHEM.middleName, ''), 
     coalesce(concat(' ', OHEM.firstName), '') 
    ) AS EmployeeName 
+0

我有類似的問題..你能幫助我嗎? http://stackoverflow.com/questions/29147569/how-to-return-null-as-0-from-mysql-using-hibernate-criteria –

相關問題