Solved

Convert Sum(IIf statement) to T-SQL

Posted on 2000-05-09
6
3,713 Views
Last Modified: 2008-11-20
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!
0
Comment
Question by:tradenut
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 7

Expert Comment

by:tchalkov
ID: 2792771
create a view , which has the case statement, and then a stored procedute which uses this view in stead of the table
0
 

Author Comment

by:tradenut
ID: 2792809
my main problem is wording the case statement.
Can you give a small example?
0
 
LVL 7

Expert Comment

by:tchalkov
ID: 2792829
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
Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

 
LVL 7

Accepted Solution

by:
simonsabin earned 50 total points
ID: 2792834
Sorry to steal the thunder but here you go

Sum(CASE WHEN table.field IS NULL THEN 1 ELSE 0 END)
 
0
 
LVL 7

Expert Comment

by:tchalkov
ID: 2792867
its ok simonsabin
you have the correct answer
0
 

Author Comment

by:tradenut
ID: 2793499
Thanks to you both for the help.

Wish I could distribute points..  =)
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Everyone has problem when going to load data into Data warehouse (EDW). They all need to confirm that data quality is good but they don't no how to proceed. Microsoft has provided new task within SSIS 2008 called "Data Profiler Task". It solve th…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

623 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question