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?

[Webinar] Streamline your web hosting managementRegister Today

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
Take Control of Web Hosting For Your Clients

As a web developer or IT admin, successfully managing multiple client accounts can be challenging. In this webinar we will look at the tools provided by Media Temple and Plesk to make managing your clients’ hosting easier.

 
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
All Courses

From novice to tech pro — start learning today.