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)
 Sumary Table

Author  Topic 

jai2808
Starting Member

27 Posts

Posted - 2008-09-30 : 02:38:19
Hi,
We have a data in the following format
UserID Status
2 A
2 A
2 R
3 A

Is is possible for the result to be in the following format using a sql query
Userid A R
2 2 1
3 1 0

Thanks,
JP

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-09-30 : 02:42:10
[code]SELECT UserID,
SUM(CASE WHEN Status='A' THEN 1 ELSE 0 END) AS A,
SUM(CASE WHEN Status='R' THEN 1 ELSE 0 END) AS R
FROM YourTable
GROUP BY UserID[/code]
Go to Top of Page

jai2808
Starting Member

27 Posts

Posted - 2008-10-01 : 09:09:27
thanks visakh16
Go to Top of Page
   

- Advertisement -