Access 2010 - Query Multiple Table Columns in one Query field to create a list based upon a specific criteria

StackOverflow https://stackoverflow.com/questions/23122126

  •  05-07-2023
  •  | 
  •  

Question

I have a query with the following tables: tblPosition, tblWorkArea, tblSkills.

  • tblPosition: ID_Position, Position
  • tblWorkArea: ID_WorkArea, WorkArea, Position
  • tblSkills: ID_WorkArea, and about 40 different skills with different number values.

I want to set up a select query to be able to produce a table given the following parameters: WorkArea and Position. For example, work area is engineering and position is technician. Table generated should list only those skills (out of the 40) that apply to these 2 parameters. ID_WorkArea is for every combination of WorkArea and Position. All of the ID_WorkArea are stored in the tblSkills along with all the skills. I want to make a select query to select certain skills given the ID_WorkArea.

The skills range from 0-30 number values. Any skill with a value of 0 means that it is not required.

My current set up for select query is as follows:

ID_WorkArea, WorkArea, Position, Skill1, skill2, etc. Criteria for WorkArea and Position are [Enter WorkArea] and [Enter Position]. Criteria for each skill is <>0.

Problem is when I run this, the IDs with at least one skill having a value of 0 does not return the data record at all. I want to see the rest of the skills, minus the skill fields that have values of 0.

Is it possible to run a single query that can generate a different number of fields depending on the parameters entered?

SQL code -

SELECT 
   tblWorkArea.ID_LaborCore, tblWorkArea.[Labor Core], 
   tblWorkArea.Position, 
   tblSkills.[Reading Schematics], tblSkills.Wiring, 
   tblSkills.[Wire Type], tblSkills.[Terminal Types], 
   tblSkills.[NEMA Ratings], tblSkills.[UL 508], 
   tblSkills.[Attention to Detail], tblSkills.[Lifting 50lbs], 
   tblSkills.[Knowledge of Procedure], tblSkills.Crimper, 
   tblSkills.[Heat Gun], tblSkills.Screwdriver, tblSkills.Stripper, 
   tblSkills.[Impact Drill], tblSkills.[Radial Saw], 
   tblSkills.Multimeter, tblSkills.[Torque Screwdriver/Wrench], 
   tblSkills.[Tape Measure], tblSkills.Vacuum, 
   tblSkills.[Drill Press], tblSkills.[Jig Saw], 
   tblSkills.[Troubleshooting Components], tblSkills.[Problem Solving], 
   tblSkills.Organization, tblSkills.[Large Panel], 
   tblSkills.[Test Procedures], tblSkills.[Functional Testing], 
   tblSkills.[Writing Test Procedures], tblSkills.[Material Management], 
   tblSkills.[Set Meter Ability], tblSkills.[Tone Generator], 
   tblSkills.[Megger Testing], tblSkills.[Network Tracer], 
   tblSkills.Components, tblSkills.Fuses, 
   tblSkills.[Heat Shrink Color Codes], tblSkills.[Proper Lug or Crimping], 
   tblSkills.[Resistors Knowledge], tblSkills.Oscilloscopes, 
   tblSkills.Waveforms, tblSkills.[Voltage Separation], 
   tblSkills.[Skill x_Stapling]
FROM 
   (tblWorkArea 
INNER JOIN 
   tblPosition ON tblWorkArea.Position = tblPosition.Postion) 
LEFT JOIN 
   tblSkills ON tblWorkArea.ID_LaborCore = tblSkills.ID_LaborCore
WHERE 
   (((tblWorkArea.[Labor Core]) = [Enter labor core]) 
   AND ((tblWorkArea.Position) = [Enter Position]) 
   AND ((tblSkills.[Reading Schematics]) <> 0) 
   AND ((tblSkills.Wiring) <> 0) 
   AND ((tblSkills.[Wire Type]) <> 0) 
   AND ((tblSkills.[Terminal Types]) <> 0) AND ((tblSkills.[NEMA Ratings])<>0) AND ((tblSkills.[UL 508])<>0) AND ((tblSkills.[Attention to Detail])<>0) AND ((tblSkills.[Lifting 50lbs])<>0) AND ((tblSkills.[Knowledge of Procedure])<>0) AND ((tblSkills.Crimper)<>0) AND ((tblSkills.[Heat Gun])<>0) AND ((tblSkills.Screwdriver)<>0) AND ((tblSkills.Stripper)<>0) AND ((tblSkills.[Impact Drill])<>0) AND ((tblSkills.[Radial Saw])<>0) AND ((tblSkills.Multimeter)<>0) AND ((tblSkills.[Torque Screwdriver/Wrench])<>0) AND ((tblSkills.[Tape Measure])<>0) AND ((tblSkills.Vacuum)<>0) AND ((tblSkills.[Drill Press])<>0) AND ((tblSkills.[Jig Saw])<>0) AND ((tblSkills.[Troubleshooting Components])<>0) AND ((tblSkills.[Problem Solving])<>0) AND ((tblSkills.Organization)<>0) AND ((tblSkills.[Large Panel])<>0) AND ((tblSkills.[Test Procedures])<>0) AND ((tblSkills.[Functional Testing])<>0) AND ((tblSkills.[Writing Test Procedures])<>0) AND ((tblSkills.[Material Management])<>0) AND ((tblSkills.[Set Meter Ability])<>0) AND ((tblSkills.[Tone Generator])<>0) AND ((tblSkills.[Megger Testing])<>0) AND ((tblSkills.[Network Tracer])<>0) AND ((tblSkills.Components)<>0) AND ((tblSkills.Fuses)<>0) AND ((tblSkills.[Heat Shrink Color Codes])<>0) AND ((tblSkills.[Proper Lug or Crimping])<>0) AND ((tblSkills.[Resistors Knowledge])<>0) AND ((tblSkills.Oscilloscopes)<>0) AND ((tblSkills.Waveforms)<>0) AND ((tblSkills.[Voltage Separation])<>0) AND ((tblSkills.[Skill x_Stapling])<>0));

Thanks!

Was it helpful?

Solution

Ah ok. It's actually your where clause that is causing this. If you need to treat each skill individually, for purposes of filtering the query and pulling back people, you're going to need to change all those ANDs to ORs in your where clause. Basically, that where clause says "only give me people who have anything but zero in ALL columns"

Try this:

SELECT  tblWorkArea.ID_LaborCore ,
        tblWorkArea.[Labor Core] ,
        tblWorkArea.Position ,
        tblSkills.[Reading Schematics] ,
        tblSkills.Wiring ,
        tblSkills.[Wire Type] ,
        tblSkills.[Terminal Types] ,
        tblSkills.[NEMA Ratings] ,
        tblSkills.[UL 508] ,
        tblSkills.[Attention to Detail] ,
        tblSkills.[Lifting 50lbs] ,
        tblSkills.[Knowledge of Procedure] ,
        tblSkills.Crimper ,
        tblSkills.[Heat Gun] ,
        tblSkills.Screwdriver ,
        tblSkills.Stripper ,
        tblSkills.[Impact Drill] ,
        tblSkills.[Radial Saw] ,
        tblSkills.Multimeter ,
        tblSkills.[Torque Screwdriver/Wrench] ,
        tblSkills.[Tape Measure] ,
        tblSkills.Vacuum ,
        tblSkills.[Drill Press] ,
        tblSkills.[Jig Saw] ,
        tblSkills.[Troubleshooting Components] ,
        tblSkills.[Problem Solving] ,
        tblSkills.Organization ,
        tblSkills.[Large Panel] ,
        tblSkills.[Test Procedures] ,
        tblSkills.[Functional Testing] ,
        tblSkills.[Writing Test Procedures] ,
        tblSkills.[Material Management] ,
        tblSkills.[Set Meter Ability] ,
        tblSkills.[Tone Generator] ,
        tblSkills.[Megger Testing] ,
        tblSkills.[Network Tracer] ,
        tblSkills.Components ,
        tblSkills.Fuses ,
        tblSkills.[Heat Shrink Color Codes] ,
        tblSkills.[Proper Lug or Crimping] ,
        tblSkills.[Resistors Knowledge] ,
        tblSkills.Oscilloscopes ,
        tblSkills.Waveforms ,
        tblSkills.[Voltage Separation] ,
        tblSkills.[Skill x_Stapling]
FROM    ( tblWorkArea
          INNER JOIN tblPosition ON tblWorkArea.Position = tblPosition.Postion
        )
        INNER JOIN tblSkills ON tblWorkArea.ID_LaborCore = tblSkills.ID_LaborCore
WHERE   ( ( ( tblWorkArea.[Labor Core] ) = [Enter labor core] )
          AND ( ( tblWorkArea.Position ) = [Enter Position] )
          AND ( ( ( tblSkills.[Reading Schematics] ) <> 0 )
                OR ( ( tblSkills.Wiring ) <> 0 )
                OR ( ( tblSkills.[Wire Type] ) <> 0 )
                OR ( ( tblSkills.[Terminal Types] ) <> 0 )
                OR ( ( tblSkills.[NEMA Ratings] ) <> 0 )
                OR ( ( tblSkills.[UL 508] ) <> 0 )
                OR ( ( tblSkills.[Attention to Detail] ) <> 0 )
                OR ( ( tblSkills.[Lifting 50lbs] ) <> 0 )
                OR ( ( tblSkills.[Knowledge of Procedure] ) <> 0 )
                OR ( ( tblSkills.Crimper ) <> 0 )
                OR ( ( tblSkills.[Heat Gun] ) <> 0 )
                OR ( ( tblSkills.Screwdriver ) <> 0 )
                OR ( ( tblSkills.Stripper ) <> 0 )
                OR ( ( tblSkills.[Impact Drill] ) <> 0 )
                OR ( ( tblSkills.[Radial Saw] ) <> 0 )
                OR ( ( tblSkills.Multimeter ) <> 0 )
                OR ( ( tblSkills.[Torque Screwdriver/Wrench] ) <> 0 )
                OR ( ( tblSkills.[Tape Measure] ) <> 0 )
                OR ( ( tblSkills.Vacuum ) <> 0 )
                OR ( ( tblSkills.[Drill Press] ) <> 0 )
                OR ( ( tblSkills.[Jig Saw] ) <> 0 )
                OR ( ( tblSkills.[Troubleshooting Components] ) <> 0 )
                OR ( ( tblSkills.[Problem Solving] ) <> 0 )
                OR ( ( tblSkills.Organization ) <> 0 )
                OR ( ( tblSkills.[Large Panel] ) <> 0 )
                OR ( ( tblSkills.[Test Procedures] ) <> 0 )
                OR ( ( tblSkills.[Functional Testing] ) <> 0 )
                OR ( ( tblSkills.[Writing Test Procedures] ) <> 0 )
                OR ( ( tblSkills.[Material Management] ) <> 0 )
                OR ( ( tblSkills.[Set Meter Ability] ) <> 0 )
                OR ( ( tblSkills.[Tone Generator] ) <> 0 )
                OR ( ( tblSkills.[Megger Testing] ) <> 0 )
                OR ( ( tblSkills.[Network Tracer] ) <> 0 )
                OR ( ( tblSkills.Components ) <> 0 )
                OR ( ( tblSkills.Fuses ) <> 0 )
                OR ( ( tblSkills.[Heat Shrink Color Codes] ) <> 0 )
                OR ( ( tblSkills.[Proper Lug or Crimping] ) <> 0 )
                OR ( ( tblSkills.[Resistors Knowledge] ) <> 0 )
                OR ( ( tblSkills.Oscilloscopes ) <> 0 )
                OR ( ( tblSkills.Waveforms ) <> 0 )
                OR ( ( tblSkills.[Voltage Separation] ) <> 0 )
                OR ( ( tblSkills.[Skill x_Stapling] ) <> 0 )
              )
        )
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top