Sorry guys I should have given more details. Hopefully this post will provide better information. Ignore the table names lists above in my op. The whole point of this is to easily identify employees who are qualified to work in certain areas. Each area can have different types of required training needed to work in that area.
In case the tablenames are a little confusing here is a summary
tblEmployees- Contains all the employees
tblTraining- Contains all the potential types of training an employee can receive
tblEmployeeTraining - Contains all the types of training an employee actually has
tblTrainingPrograms- Contains all the different areas an employee can work in
tblTrainingProgramModules - Contains all the different types of training an area requires.
Here are some create scripts as well as some insert data. Given the data below
Floor 1 Area Cleaning should only return Jim
Floor 2 Area Cleaning should return no one
Floor 3 Area Cleaning should return only Jim again
CREATE TABLE [dbo].[tblEmployees] (
[EmployeeID] int NOT NULL PRIMARY KEY,
[FirstName] varchar(50) COLLATE Latin1_General_CI_AS NOT NULL,
[LastName] varchar(50) COLLATE Latin1_General_CI_AS NOT NULL
)
ON [PRIMARY]
GO
INSERT INTO [tblEmployees]
([EmployeeID],[FirstName],[LastName])
VALUES(1111111,'Jim','Smith')
GO
INSERT INTO [tblEmployees]
([EmployeeID],[FirstName],[LastName])
VALUES(2222222,'Mary','Smith')
GO
INSERT INTO [tblEmployees]
([EmployeeID],[FirstName],[LastName])
VALUES(3333333,'Joe','Brown')
GO
COMMIT
GO
CREATE TABLE [dbo].[tblTraining] (
[Training_ID] int IDENTITY(1, 1) NOT NULL PRIMARY KEY,
[TrainingDescription] varchar(100) COLLATE Latin1_General_CI_AS NOT NULL
)
ON [PRIMARY]
GO
INSERT INTO [tblTraining]
([Training_ID],[TrainingDescription])
VALUES(1,'Room Cleaning')
GO
INSERT INTO [tblTraining]
([Training_ID],[TrainingDescription])
VALUES(2,'Mechanical Room Cleaning')
GO
INSERT INTO [tblTraining]
([Training_ID],[TrainingDescription])
VALUES(3,'Common Area Cleaning')
GO
COMMIT
GO
CREATE TABLE [dbo].[tblEmployeeTraining] (
[EmpTraining_ID] int IDENTITY(1, 1) NOT NULL PRIMARY KEY,
[EmployeeID] int NOT NULL,
[TrainingID] int NOT NULL
)
ON [PRIMARY]
GO
INSERT INTO [tblEmployeeTraining]
([EmpTraining_ID],[EmployeeID],[TrainingID])
VALUES(1,1111111,1)
GO
INSERT INTO [tblEmployeeTraining]
([EmpTraining_ID],[EmployeeID],[TrainingID])
VALUES(2,1111111,2)
GO
INSERT INTO [tblEmployeeTraining]
([EmpTraining_ID],[EmployeeID],[TrainingID])
VALUES(3,2222222,2)
GO
INSERT INTO [tblEmployeeTraining]
([EmpTraining_ID],[EmployeeID],[TrainingID])
VALUES(4,3333333,3)
GO
COMMIT
GO
CREATE TABLE [dbo].[tblTrainingPrograms] (
[TrainingProgram_ID] int IDENTITY(1, 1) NOT NULL PRIMARY KEY,
[ProgramDescription] varchar(100) COLLATE Latin1_General_CI_AS NOT NULL
)
ON [PRIMARY]
GO
INSERT INTO [tblTrainingPrograms]
([TrainingProgram_ID],[ProgramDescription])
VALUES(1,'Floor 1 Area Cleaning')
GO
INSERT INTO [tblTrainingPrograms]
([TrainingProgram_ID],[ProgramDescription])
VALUES(2,'Floor 2 Area Cleaning')
GO
INSERT INTO [tblTrainingPrograms]
([TrainingProgram_ID],[ProgramDescription])
VALUES(3,'Floor 3 Area Cleaning')
GO
COMMIT
GO
CREATE TABLE [dbo].[tblTrainingProgramModules] (
[TrainingModule_ID] int IDENTITY(1, 1) NOT NULL PRIMARY KEY,
[TrainingProgramID] int NOT NULL,
[TrainingID] int NOT NULL
)
ON [PRIMARY]
GO
INSERT INTO [tblTrainingProgramModules]
([TrainingModule_ID],[TrainingProgramID],[TrainingID])
VALUES(1,1,1)
GO
INSERT INTO [tblTrainingProgramModules]
([TrainingModule_ID],[TrainingProgramID],[TrainingID])
VALUES(2,1,2)
GO
INSERT INTO [tblTrainingProgramModules]
([TrainingModule_ID],[TrainingProgramID],[TrainingID])
VALUES(3,2,2)
GO
INSERT INTO [tblTrainingProgramModules]
([TrainingModule_ID],[TrainingProgramID],[TrainingID])
VALUES(4,2,3)
GO
INSERT INTO [tblTrainingProgramModules]
([TrainingModule_ID],[TrainingProgramID],[TrainingID])
VALUES(5,3,1)
GO
COMMIT
GO