SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

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

jgandara
Starting Member

18 Posts

Posted - 09/02/2005 :  11:32:59  Show Profile  Reply with Quote
I have a table called Groups:
CompanyId,GroupId,GroupDesc,MaxUsers

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:
10,1,Admins,10
10,2,President,1
10,3,Manager,5

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.

nathans
Aged Yak Warrior

USA
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:
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx


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  
 New 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.09 seconds. Powered By: Snitz Forums 2000