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'".

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

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

Answers


The MySQL equivalent of ISNULL is IFNULL

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

Maybe also look at SQL NULL Functions

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

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


I would suggest that you switch to the ANSI standard function 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():

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

I was getting an error when running JUnit tests against a query which had ISNULL(value) with the error saying ISNULL needed two parameters. I fixed this by changing the query to have value is null and the code works the same while the tests now work.


Need Your Help

IPython (Jupyter) notebook producing ghost line in all equations

ipython ipython-notebook jupyter jupyter-notebook mathjax

I installed IPython / Jupyter using pip on a new machine (Macbook Air with El Capitan). In a fairly simple notebook of mine (created with the same version of the whole stack) all equations, inline ...

How can I correct MySQL Load Error

mysql csv import load local

I'm not quite sure a similar question to this was closed by I'm trying to execute the following MySQL program.