Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 Totalling Results

Author  Topic 

Leigh79
Starting Member

28 Posts

Posted - 2007-10-31 : 07:58:26
Hi Guys

I have a table which allows me to track which members of staff are capturing customers email addresses.

I now want to produce a 'League Table' to show which are the best performing areas.

The information stored in the table is id, staff_id, staff_dept, email_address.

What I would like the end result to be is

Department, Total Logged (COUNT of id), Total Real Addresses (COUNT OF id WHERE email_address <> 'NA'), Total Default Addresses (COUNT OF id WHERE email_address = 'NA')

Can anyone tell me what is the best way to go about this?

harsh_athalye
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2007-10-31 : 08:08:52
[code]Select
staff_dept as Department,
sum(case when email_address <> 'NA' then 1 else 0 end) as [Total Real Addresses],
sum(case when email_address = 'NA' then 1 else 0 end) as [Total Default Addresses]
from Table
Group by staff_dept[/code]

Harsh Athalye
India.
"The IMPOSSIBLE is often UNTRIED"
Go to Top of Page

Leigh79
Starting Member

28 Posts

Posted - 2007-10-31 : 08:10:26
Hi Harsh

That is exactly what I needed, thanks for your help, and fast response!
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2007-10-31 : 08:22:55
Read about Cross-tab reports in sql server help file for more informations

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -