Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Solved

Posted on 2013-01-28

I have an elaborate SQL string below that calculates the number or days in my attendance grid that had activity in it. In the output it shows several records of the committee. How can I show Distinct Committees in the output?

```
SELECT committee,Activity, COUNT([Last Name]) as Participants,
CASE WHEN SUM( [1]) > 0 THEN 1 ELSE 0 END + CASE WHEN SUM( [2]) > 0 THEN 1 ELSE 0 END + CASE WHEN SUM( [3]) > 0 THEN 1 ELSE 0 END + CASE WHEN SUM( [4]) > 0 THEN 1 ELSE 0 END + CASE WHEN SUM( [5]) > 0 THEN 1 ELSE 0 END + CASE WHEN SUM( [6]) > 0 THEN 1 ELSE 0 END + CASE WHEN SUM( [7]) > 0 THEN 1 ELSE 0 END + CASE WHEN SUM( [8]) > 0 THEN 1 ELSE 0 END + CASE WHEN SUM( [9]) > 0 THEN 1 ELSE 0 END + CASE WHEN SUM( [10]) > 0 THEN 1 ELSE 0 END + CASE WHEN SUM( [11]) > 0 THEN 1 ELSE 0 END + CASE WHEN SUM( [12]) > 0 THEN 1 ELSE 0 END + CASE WHEN SUM( [13]) > 0 THEN 1 ELSE 0 END + CASE WHEN SUM( [14]) > 0 THEN 1 ELSE 0 END + CASE WHEN SUM( [15]) > 0 THEN 1 ELSE 0 END + CASE WHEN SUM( [16]) > 0 THEN 1 ELSE 0 END + CASE WHEN SUM( [17]) > 0 THEN 1 ELSE 0 END + CASE WHEN SUM( [18]) > 0 THEN 1 ELSE 0 END +
CASE WHEN SUM( [19]) > 0 THEN 1 ELSE 0 END + CASE WHEN SUM( [20]) > 0 THEN 1 ELSE 0 END + CASE WHEN SUM( [21]) > 0 THEN 1 ELSE 0 END + CASE WHEN SUM( [22]) > 0 THEN 1 ELSE 0 END + CASE WHEN SUM( [23]) > 0 THEN 1 ELSE 0 END + CASE WHEN SUM( [24]) > 0 THEN 1 ELSE 0 END + CASE WHEN SUM( [25]) > 0 THEN 1 ELSE 0 END + CASE WHEN SUM( [26]) > 0 THEN 1 ELSE 0 END + CASE WHEN SUM( [27]) > 0 THEN 1 ELSE 0 END + CASE WHEN SUM( [28]) > 0 THEN 1 ELSE 0 END + CASE WHEN SUM( [29]) > 0 THEN 1 ELSE 0 END + CASE WHEN SUM( [30]) > 0 THEN 1 ELSE 0 END + CASE WHEN SUM([31]) > 0 THEN 1 ELSE 0 END AS #Days_With_Activity
FROM AttendanceGrid
where 7 <= datediff(year, Age , EntryTime) And Fiscal = 2013 and Total > 0 and not Committee like 'ivpa%' and Month IN ('July', 'August', 'September', 'October', 'November','December')
GROUP BY activity, Committee order by Committee
```

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

2 Comments

Here's a good link that should point you in the right direction.

http://blog.sqlauthority.com/2012/07/27/sql-server-query-to-get-unique-distinct-data-based-on-condition-eleminate-duplicate-data-from-resultset/

If you post the table schema, some sample data and indicate what level of distinction you are wanting, I can help you more.

And determining this one detail, may help you find your own answer. What makes the data distinct?

Regards,

Michael

see also this article for explanations:

http://www.experts-exchange.com/Database/Miscellaneous/A_3203-DISTINCT-vs-GROUP-BY-and-why-does-it-not-work-for-my-query.html

Question has a verified solution.

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

Course of the Month15 days, 4 hours left to enroll

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