Convert Sum(IIf statement) to T-SQL

I have an Access SQL query I'd like to convert to a stored procedure in SQL Server 7.  I'm pretty sure it requires a case when statement, but I'm stuck!

How can I translate this statement to t-sql?

Sum(IIf(IsNull(table.field),1,0)) as SumOfEmptyField

Thanks much!
tradenutAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
simonsabinConnect With a Mentor Commented:
Sorry to steal the thunder but here you go

Sum(CASE WHEN table.field IS NULL THEN 1 ELSE 0 END)
 
0
 
tchalkovCommented:
create a view , which has the case statement, and then a stored procedute which uses this view in stead of the table
0
 
tradenutAuthor Commented:
my main problem is wording the case statement.
Can you give a small example?
0
What Kind of Coding Program is Right for You?

There are many ways to learn to code these days. From coding bootcamps like Flatiron School to online courses to totally free beginner resources. The best way to learn to code depends on many factors, but the most important one is you. See what course is best for you.

 
tchalkovCommented:
select t=case type
               when 1 then 'OK'
               when 2 then 'Not OK'
         else 'Unknown'
         end

there are a lot of examples in books online - the help of SQL Server
tell me what exactly what you want to do if you want more specific help

0
 
tchalkovCommented:
its ok simonsabin
you have the correct answer
0
 
tradenutAuthor Commented:
Thanks to you both for the help.

Wish I could distribute points..  =)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.