调用本机函数'ISNULL'时参数计数不正确

[英]Incorrect parameter count in the call to native function 'ISNULL'


I have a query that I am trying to convert to MySQL from MS SQL Server 2008. It runs fine on MSSQL, I get the error "Incorrect parameter count in the call to native function 'ISNULL'".

我有一个查询,我试图从MS SQL Server 2008转换为MySQL。它在MSSQL上正常运行,我得到错误“调用本机函数'ISNULL'时参数计数不正确”。

How do I solve this?

我该如何解决这个问题?

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

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

2 个解决方案

#1


28  

The MySQL equivalent of ISNULL is IFNULL

ISNULL的MySQL等价物是IFNULL

If expr1 is not NULL, IFNULL() returns expr1; otherwise it returns expr2.

如果expr1不为NULL,则IFNULL()返回expr1;否则返回expr2。

Maybe also look at SQL NULL Functions

也许还看看SQL NULL函数

The ISNULL from MySQL is used to check if a value is null

MySQL的ISNULL用于检查值是否为空

If expr is NULL, ISNULL() returns 1, otherwise it returns 0.

如果expr为NULL,则ISNULL()返回1,否则返回0。

#2


2  

I would suggest that you switch to the ANSI standard function coalesce():

我建议您切换到ANSI标准函数coalesce():

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

You could also make your query easier to read by including table aliases.

您还可以通过包含表别名来使查询更容易阅读。

EDIT:

编辑:

As a note, I seemed to have missed the direction of conversion. The MySQL query would use concat():

作为一个说明,我似乎错过了转换的方向。 MySQL查询将使用concat():

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

注意!

本站翻译的文章,版权归属于本站,未经许可禁止转摘,转摘请注明本文地址:http://www.itdaan.com/blog/2014/01/27/dfbee3fced6e13e58d1b4b1f373846d9.html



 
© 2014-2018 ITdaan.com 粤ICP备14056181号