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.

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | Active Topics | Members | Search | Forum FAQ
Save Password
Forgot your Password?

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Getting groups left based on a limit
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Starting Member

18 Posts

Posted - 09/02/2005 :  11:32:59  Show Profile  Reply with Quote
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 - 09/02/2005 :  17:06:12  Show Profile  Reply with Quote
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

Edited by - nathans on 09/02/2005 17:07:38
Go to Top of Page
  Previous Topic Topic Next Topic  
 Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.02 seconds. Powered By: Snitz Forums 2000