- Feb 13, 2003
- 26,256
- 406
- 126
I have a table of users (just under 10,000 records) and a table of groups (about 5-6 records). I need to go through each user and determine which group(s) they should be placed in. This is decided by the data in several of the user's columns and the criteria for the group.
For example, a user has country "US" and job title "Manager". A group has criteria "Country" and values "US,CA,MX". Another group has criteria "JobTitle" and values "Owner,Administrator".
The script needs to check the values for the user's columns (Country and JobTitle), and if the values are contained in a group's values, the user is assigned to that group (record written to another table with the user's alias and group's ID). So in this case, the user gets placed in the first group but not the second.
I was thinking about using cursors to accomplish this since a lot of logic and checking is involved. Use one cursor to iterate through the users and another to iterate through the groups, for each user. This isn't exactly efficient, but the script is only run once a week and it does not need to be real fast. A run time of say 30 seconds is even acceptable.
Any thoughts on this? I'm no SQL expert so I'm not sure at all how I'd do this without cursors.
For example, a user has country "US" and job title "Manager". A group has criteria "Country" and values "US,CA,MX". Another group has criteria "JobTitle" and values "Owner,Administrator".
The script needs to check the values for the user's columns (Country and JobTitle), and if the values are contained in a group's values, the user is assigned to that group (record written to another table with the user's alias and group's ID). So in this case, the user gets placed in the first group but not the second.
I was thinking about using cursors to accomplish this since a lot of logic and checking is involved. Use one cursor to iterate through the users and another to iterate through the groups, for each user. This isn't exactly efficient, but the script is only run once a week and it does not need to be real fast. A run time of say 30 seconds is even acceptable.
Any thoughts on this? I'm no SQL expert so I'm not sure at all how I'd do this without cursors.
