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.
Author |
Topic |
nidabp
Starting Member
15 Posts |
Posted - 2011-02-20 : 03:19:10
|
Hi, I have 2 tables, a user table and a project table.User table has all the list of Ids and Names.The project table has fields - project id, Client Manager,User Manager and Status.The status can be active, inactive, closed.The Client Manger and User Manager are the userids from the user table.For all the users in the user table, I need to get the count of the projects for which the status is active or inactive, for which a user is either a client manager or User Manager. If he is both, the count should be taken as 1.the tables.useruserid Name1 x2 y3 zproject tableprojectid clientManager UserManager Status1 x y active2 x z inactive3 y y active4 z x inactive5 x x active6 z y inactiveThe result table should look likeuser active inactivex 2 2y 2 1z 0 3Thanx |
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2011-02-20 : 03:44:53
|
SELECT clientManager, SUM(CASE WHEN [Status] = 'Active' THEN 1 ELSE 0 END) AS [Active],SUM(CASE WHEN [Status] = 'Inactive' THEN 1 ELSE 0 END) AS InactiveFROM dbo.Table1GROUP BY clientManager N 56°04'39.26"E 12°55'05.63" |
 |
|
|
|
|