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
 SQL Server Development (2000)
 Query

Author  Topic 

sardinka
Posting Yak Master

142 Posts

Posted - 2004-07-06 : 11:04:11
I have a query where my results displays like this:
Answer ID
Yes 12
No 12
Yes 1
Yes 1...
I need to display my results like this:
Answer ID
Yes No 12
Yes No 1...
How do I do this?

Seventhnight
Master Smack Fu Yak Hacker

2878 Posts

Posted - 2004-07-06 : 11:53:47
Your sample data doesn't make sense...

You have 'Yes' x2, but in your result you still have 'Yes No'

What are you really trying to do??

I will stab at it and say you want to know how many Yes and how many No for a given Id...
With that assumption:
Select
Id,
YesCnt = sum(Yes),
NoCnt = sum(No)
From
(
Select
Id,
Yes = case when Answer='Yes' then 1 else 0 end,
No = case when Answer='No' then 1 else 0 end,
From ResultsTable
) as A
Group By Id

Corey
Go to Top of Page
   

- Advertisement -