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 |
Auris
Starting Member
7 Posts |
Posted - 2012-04-04 : 04:17:00
|
Hi there, so my question is fairly simple i guess but i cant figure out how to do it properly. So here is the data sampleData SampleUniqueId GroupId RoleId1 A R12 A R23 A R84 B R85 B R56 B R17 B R28 C R29 C R310 D R1So uniqueId is primary key and its unique, groupId is just group the records belongs to and RoleId determines which roles have access to particular group. My goal is to select all groups that doesnt have role of R8 assigned to them? no how do i acomplish that ? This is urgent! please provide me with possible approach.Life is hard. It's even harder if you're stupid. |
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2012-04-04 : 04:22:48
|
[code]select distinct GroupIdfrom [data sample] swhere not exists ( select * from [data sample] x where x.GroupId = s.GroupId and x.RoleId = 'RB' )[/code] KH[spoiler]Time is always against us[/spoiler] |
 |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2012-04-04 : 18:34:04
|
simply this?select GroupIdfrom [data sample] group by GroupIdhaving count(case when RoleId = 'R8' then 1 else null end) =0 ------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
Auris
Starting Member
7 Posts |
Posted - 2012-04-05 : 03:49:05
|
this ones an interesting approach, thank you for you answers guys.quote: Originally posted by visakh16 simply this?select GroupIdfrom [data sample] group by GroupIdhaving count(case when RoleId = 'R8' then 1 else null end) =0 ------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/
Life is hard. It's even harder if you're stupid. |
 |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2012-04-05 : 12:30:44
|
welcome------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
raj.prabhu001
Starting Member
16 Posts |
Posted - 2012-04-07 : 05:06:10
|
select GroupIdfrom [data sample] group by GroupIdhaving count(case when RoleId = 'R8' then 1 else null end) =0can you plz explain how does having count(case when RoleId = 'R8' then 1 else null end) =0will not return roleid = r8 |
 |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2012-04-08 : 18:11:43
|
it will not return roleid=r8 but it will returns all the groups (groupid values) where RoleId='R8' was not involved in it.------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
|
|