1

I have misplaced something in the ISNULL() function and need another set of eyes to find it. I've stared at it so much I've become brainlocked (I know what ISNULL() is, this is just a simple syntax error)

(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
    @jpm0004, your question was ambiguous as it wasn't clearly stated in the body what you were wanting help with. We didn't know if you actually understood what ISNULL() was supposed to do, or if you just needed help tracking down a syntax error. Instead of getting snippy, try to help us help you next time. Commented Jun 6, 2012 at 15:07
  • Alright, I edited it. I thought the question was understood, but I understand how it may have been confusing. Sorry everyone! Thanks for the help! Commented Jun 6, 2012 at 15:13

4 Answers 4

2

The ISNULL() function requires two arguments which you can see here:

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

The first one is the expression being tested, the second is the value to return if the expression tested evaluates to NULL.

Your second ISNULL() function only specifies one parameter:

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

You should try:

ISNULL((case when CONVERT(smalldatetime,dModLast,101) 
       BETWEEN '2012-03-01' AND '2012-03-10' then 1 else 0 end), 0)
Sign up to request clarification or add additional context in comments.

1 Comment

+1 This is a better answer, complete with reference material.
1

Try this:

(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

1 Comment

Would have been better if you'd explained what was wrong and possibly citing reference material.
1

You have a paren in the wrong spot:

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

Notice after the 'end' of your CASE statement

Comments

0

Here is the answer... I figured it out.

Notice the difference...

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

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

1 Comment

After posting the answer... seems 3 other people answered before me... they were all correct. Thanks to all!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.