Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Wrong number of arguments with SQL ISNULL() on Access DB

I have this query in VB application on Access DB:

  SELECT DISTINCT Specialization, MAX(a.faultZone) AS faultZone, ISNULL(a.faultCount, 0) AS NoOfFaults  FROM Technicians AS t 
    LEFT JOIN 
             ( 
            SELECT DISTINCT Faults.[Type] AS faultType, MAX(Faults.[Zone]) AS faultZone, COUNT(Faults.[Type]) AS faultCount 
            FROM Faults "
            WHERE Faults.[Zone] = 8 " ' this value will be from variable
            GROUP BY Faults.[Type] "
            ) AS a 
    ON (t.Specialization = a.faultType) 
    WHERE t.specialization <> 'None' "
    GROUP BY a.faultCount, t.Specialization 

It gives following problem that I can't solve...

"Wrong number of arguments used with function in query expression 'ISNULL(a.faultCount, 0'."

What I want to achieve is simply set value of NoOFFaults to zero, which would mean there are no faults in particular Zone.

Thank You

like image 416
JanT Avatar asked Nov 29 '12 20:11

JanT


People also ask

How many arguments does the Isnull function take?

The ISNULL() function accepts two arguments: expression is an expression of any type that is checked for NULL . replacement is the value to be returned if the expression is NULL . The replacement must be convertible to a value of the type of the expression .

Which is better coalesce or Isnull?

COALESCE and ISNULL advantage that COALESCE has over ISNULL is that it supports more than two inputs, whereas ISNULL supports only two. Another advantage of COALESCE is that it's a standard function (namely, defined by the ISO/ANSI SQL standards), whereas ISNULL is T-SQL–specific.

What is Isnull () operator in SQL?

Definition and Usage. The ISNULL() function returns a specified value if the expression is NULL. If the expression is NOT NULL, this function returns the expression.

What should be the function to check whether a particular value is not NULL in SQL?

The IS NOT NULL operator is used to test for non-empty values (NOT NULL values).


3 Answers

Just to add my two cents, and while I like the simple syntax of Nz(), if you seek trouble free performance, both IsNull() and NZ() should be avoided in favor of Is Null:
IIF(a.faultCount Is Null, 0, a.faultCount).

See the excellent explanation here: http://allenbrowne.com/QueryPerfIssue.html

Also, if your tables are in SQL Server or Oracle, using Nz() will force more of the query to be executed locally, with a HUGE performance impact.

like image 157
iDevlop Avatar answered Oct 23 '22 01:10

iDevlop


Microsoft Access' version of IsNull is different than most SQL versions; it simply returns TRUE if the value is NULL, and FALSE if it isn't.

You need to basically build your own using IIF():

IIF(ISNULL(a.faultCount), 0, a.faultCount)
like image 22
LittleBobbyTables - Au Revoir Avatar answered Oct 23 '22 02:10

LittleBobbyTables - Au Revoir


I think that you are looking for the nz function

Nz(a.faultCount, 0)

will return 0 if the value is null

like image 5
HelloW Avatar answered Oct 23 '22 03:10

HelloW