[英]Wrong number of arguments with SQL ISNULL() on Access DB
I have this query in VB application on Access DB: 我在Access DB上的VB应用程序中有这个查询:
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'." “查询表达式中的函数使用的参数数量错误'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. 我想要实现的只是将NoOFFaults
值设置为零,这意味着特定区域没有故障。
Thank You 谢谢
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: 只是为了增加我的两分钱,虽然我喜欢Nz()的简单语法,但如果你寻求无故障性能,应该避免使用IsNull()和NZ()来支持Is Null:
IIF(a.faultCount Is Null, 0, a.faultCount)
. IIF(a.faultCount Is Null, 0, a.faultCount)
。
See the excellent explanation here: http://allenbrowne.com/QueryPerfIssue.html 请参阅此处的优秀解释: 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. 此外,如果您的表位于SQL Server或Oracle中,则使用Nz()将强制在本地执行更多查询,从而对性能产生巨大影响。
Microsoft Access' version of IsNull
is different than most SQL versions; Microsoft Access的IsNull
版本与大多数SQL版本不同; it simply returns TRUE if the value is NULL, and FALSE if it isn't . 如果值为NULL,它只返回TRUE,如果不是则返回FALSE 。
You need to basically build your own using IIF()
: 你需要基本上使用IIF()
构建自己的:
IIF(ISNULL(a.faultCount), 0, a.faultCount)
I think that you are looking for the nz function 我认为你正在寻找nz功能
Nz(a.faultCount, 0)
will return 0 if the value is null 如果值为null,则返回0
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.