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
 General SQL Server Forums
 New to SQL Server Programming
 SQL Query Looping

Author  Topic 

vikranth9b
Starting Member

2 Posts

Posted - 2008-04-09 : 14:32:29
This is the TABLE I have

ID BRANCH STATUS

1 A ACTIVE
1 B INACTIVE
1 C INACTIVE
2 B INACTIVE
2 C INACTIVE
2 D INACTIVE
3 A ACTIVE
3 B ACTIVE
3 C ACTIVE
4 B ACTIVE
5 D INACTIVE
----------------------------------------------------------------
Following is the desired View that I need for the above table.
Any ID which has atleast one ACTIVE branch will have ACTIVE status and any company which have all of its branches INACTIVE will have INACTIVE status. Thanks for your help

ID STATUS

1 ACTIVE
2 INACTIVE
3 ACTIVE
4 ACTIVE
5 INACTIVE

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2008-04-09 : 14:50:30
SELECT ID, CASE MAX(CASE WHEN Status = 'Active' THEN 1 ELSE 0 END)
WHEN 1 THEN 'Active'
ELSE 'Inactive'
END AS Status
FROM Table
GROUP BY ID



E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page

vikranth9b
Starting Member

2 Posts

Posted - 2008-04-09 : 14:59:24
Thanks Peso
Go to Top of Page
   

- Advertisement -