Please start any new threads on our new site at 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)
 Getting groups left based on a limit

Author  Topic 

Starting Member

18 Posts

Posted - 2005-09-02 : 11:32:59
I have a table called Groups:

also I have a users table:
CompanyId,UserId, GroupId

One user belongs only to one group.

So I need to get the groups available based on the number of existing users, for example:

Group Table Info:

If I already have a president user for that company, I want to get a list of all available groups: Admins and Managers. If I already have 5 managers, then the query would return the administrator group only.

Aged Yak Warrior

938 Posts

Posted - 2005-09-02 : 17:06:12
Hi there. It would help a lot if you formatted your question with sample data and desired resultset. You can read about proper posting techniques here:

Here, ill get you started:

declare @groups table (CompanyId int, GroupId int, GroupDesc varchar(100), MaxUsers int)
declare @users table (CompanyId int, UserId int, GroupId int)

insert into @groups
select 10, 1, 'Admins', 10 union
select 10, 2, 'President', 1 union
select 10, 3, 'Manager', 5

Nathan Skerl
Go to Top of Page

- Advertisement -