ISNULL()函数需要两个参数?简单解决方案

时间:2012-06-06 14:55:11

标签: sql isnull

我在ISNULL()函数中放错了位置,需要另外一组眼睛才能找到它。我已经盯着它了,我已经成为脑力劳动(我知道ISNULL()是什么,这只是一个简单的语法错误)

(SELECT tn.teamtext, tn.teamid, ISNULL(sum(ISNULL(case when CONVERT(smalldatetime,dModLast,101) BETWEEN '2012-03-01' AND '2012-03-10' then 1 else 0 end), 0), 0) AS cnt3
  FROM teamnames AS tn 
    LEFT OUTER JOIN caseaudit AS ca
    ON tn.teamID = ca.referteamID2
  WHERE ca.referteamid1 <> ca.referteamid2 AND isactive = 1 AND groupid = 18 AND accountid = 2 AND referteamid1 = 31 AND auditnote <> 'Suspend Case'
  GROUP BY tn.teamtext, tn.teamid) AS c

4 个答案:

答案 0 :(得分:2)

ISNULL()函数需要两个参数,您可以在此处看到:

  

http://msdn.microsoft.com/library/ms184325.aspx

第一个是正在测试的表达式,第二个是在测试表达式求值为NULL时要返回的值。

您的第二个ISNULL()函数仅指定一个参数:

ISNULL(case when CONVERT(smalldatetime,dModLast,101) 
       BETWEEN '2012-03-01' AND '2012-03-10' then 1 else 0 end)

你应该尝试:

ISNULL((case when CONVERT(smalldatetime,dModLast,101) 
       BETWEEN '2012-03-01' AND '2012-03-10' then 1 else 0 end), 0)

答案 1 :(得分:1)

试试这个:

(SELECT tn.teamtext, tn.teamid, ISNULL(sum(ISNULL(case when CONVERT(smalldatetime,dModLast,101) BETWEEN '2012-03-01' AND '2012-03-10' then 1 else 0 end, 0)), 0) AS cnt3
  FROM teamnames AS tn 
    LEFT OUTER JOIN caseaudit AS ca
    ON tn.teamID = ca.referteamID2
  WHERE ca.referteamid1 <> ca.referteamid2 AND isactive = 1 AND groupid = 18 AND accountid = 2 AND referteamid1 = 31 AND auditnote <> 'Suspend Case'
  GROUP BY tn.teamtext, tn.teamid) AS c

答案 2 :(得分:1)

你有错误的地方:

ISNULL(sum(ISNULL(case when CONVERT(smalldatetime,dModLast,101) BETWEEN '2012-03-01' AND '2012-03-10' then 1 else 0 end , 0)), 0) AS cnt3

在CASE声明的“结束”之后注意

答案 3 :(得分:0)

这是答案......我明白了。

注意区别......

原件: ISNULL(总和(ISNULL(CONVERT(smalldatetime,dModLast,101)在'2012-03-01'和'2012-03-10'之间的情况然后1其他0结束), 0), 0)

修 ISNULL(总和(ISNULL(CONVERT(smalldatetime,dModLast,101)在'2012-03-01'和'2012-03-10'之间的情况,然后1其他0结束, 0)),0) < / p>