Query to Determine if Course is Taken

Hi, I have a table that lists courses an employee has taken. I also have a 
list of courses, when then expire and what their retraining course should be. 
Now I need to determine if the employee has taken not only the original 
course, but the retrained course when they're on separate lines.

So.. if he's taken course 123 which expires in 12 months. Then he takes 
course 124. It shows in the list of courses that he's taken that 124 was also 
completed. However, my flag just determines that 123 is expired. I need that 
flag to not show if 124 has been taken.

Hope that's a complete enough explanation...

-- 
THX cs
0
Utf
2/23/2008 12:24:00 AM
access 16762 articles. 2 followers. Follow

4 Replies
509 Views

Similar Articles

[PageSpeed] 11

On Fri, 22 Feb 2008 16:24:00 -0800, Cydney
<Cydney@discussions.microsoft.com> wrote:

This sounds like a Union query. In English:
select all active courses taken
plus  [this becomes your Union statement]
select all inactive courses taken where there is no retraining course
in the first set.  [use: ... where not in (select <the_first_set>)]

The exact statement depends on the exact tables, and probably also on
a bit more exact definition of the problem. Hopefully the above will
get you started.

-Tom.


>Hi, I have a table that lists courses an employee has taken. I also have a 
>list of courses, when then expire and what their retraining course should be. 
>Now I need to determine if the employee has taken not only the original 
>course, but the retrained course when they're on separate lines.
>
>So.. if he's taken course 123 which expires in 12 months. Then he takes 
>course 124. It shows in the list of courses that he's taken that 124 was also 
>completed. However, my flag just determines that 123 is expired. I need that 
>flag to not show if 124 has been taken.
>
>Hope that's a complete enough explanation...
0
Tom
2/23/2008 3:55:42 AM
If I understand you correctly you want to return rows where no other row 
exists for that employee where the course taken is the retaining course 
specified in the first row.  The solution to this type of problem is to 
restrict the rows returned by a query by means of a correlated subquery.  
Lets assume your table is called CoursesTaken and has, amongst others, 
columns EmployeeID, CourseTakenID, RetrainingCourseID.  The first column 
would reference the primary key of an Employees table and the other two 
columns the primary key of  a Courses table.  The CoursesTaken table in fact 
models a many-to-many relationship type between the other two.  So a query 
would be like this:

SELECT *
FROM CoursesTaken AS CT1
WHERE NOT EXISTS
    (SELECT *
     FROM CoursesTaken AS CT2
     WHERE CT2.EmployeeID = CT1.EmployeeID
     AND CT2.CourseTakenID = CT1.RetrainingCourseID);

The above would return just those rows where an employee has not yet taken 
the specified retraining course.  An alternative solution would be to include 
the subquery in the outer query's SELECT clause.  This would return rows 
showing all courses taken, but with an extra column showing the specified 
retraining course only if taken; otherwise the column would be null:

SELECT EmployeeID, CourseTakenID,
    (SELECT RetainingCourseID
     FROM CoursesTaken AS CT2
     WHERE CT2.EmployeeID = CT1.EmployeeID
     AND CT2.CourseTakenID = CT1.RetrainingCourseID)
AS RetrainingCourseTaken
FROM CoursesTaken AS CT1;

The above queries use only the one table, but in reality of course (no pun 
intended!) you'd join the Employees and Courses tables to the CoursesTaken 
table in the outer query of the first query to show the employee's name and 
the course title.  In the case of the second query these tables would again 
be joined to the CoursesTaken table in the outer query, but you'd also join 
the Courses table to the CoursesTaken table in the subquery and return the 
course title rather than the CourseID as RetrainingCourseTaken column.

Ken Sheridan
Stafford, England 

"Cydney" wrote:

> Hi, I have a table that lists courses an employee has taken. I also have a 
> list of courses, when then expire and what their retraining course should be. 
> Now I need to determine if the employee has taken not only the original 
> course, but the retrained course when they're on separate lines.
> 
> So.. if he's taken course 123 which expires in 12 months. Then he takes 
> course 124. It shows in the list of courses that he's taken that 124 was also 
> completed. However, my flag just determines that 123 is expired. I need that 
> flag to not show if 124 has been taken.
> 
> Hope that's a complete enough explanation...
> 
> -- 
> THX cs

0
Utf
2/23/2008 11:36:00 AM
Thanks so much! This set me on the right track. 
-- 
THX cs


"Ken Sheridan" wrote:

> If I understand you correctly you want to return rows where no other row 
> exists for that employee where the course taken is the retaining course 
> specified in the first row.  The solution to this type of problem is to 
> restrict the rows returned by a query by means of a correlated subquery.  
> Lets assume your table is called CoursesTaken and has, amongst others, 
> columns EmployeeID, CourseTakenID, RetrainingCourseID.  The first column 
> would reference the primary key of an Employees table and the other two 
> columns the primary key of  a Courses table.  The CoursesTaken table in fact 
> models a many-to-many relationship type between the other two.  So a query 
> would be like this:
> 
> SELECT *
> FROM CoursesTaken AS CT1
> WHERE NOT EXISTS
>     (SELECT *
>      FROM CoursesTaken AS CT2
>      WHERE CT2.EmployeeID = CT1.EmployeeID
>      AND CT2.CourseTakenID = CT1.RetrainingCourseID);
> 
> The above would return just those rows where an employee has not yet taken 
> the specified retraining course.  An alternative solution would be to include 
> the subquery in the outer query's SELECT clause.  This would return rows 
> showing all courses taken, but with an extra column showing the specified 
> retraining course only if taken; otherwise the column would be null:
> 
> SELECT EmployeeID, CourseTakenID,
>     (SELECT RetainingCourseID
>      FROM CoursesTaken AS CT2
>      WHERE CT2.EmployeeID = CT1.EmployeeID
>      AND CT2.CourseTakenID = CT1.RetrainingCourseID)
> AS RetrainingCourseTaken
> FROM CoursesTaken AS CT1;
> 
> The above queries use only the one table, but in reality of course (no pun 
> intended!) you'd join the Employees and Courses tables to the CoursesTaken 
> table in the outer query of the first query to show the employee's name and 
> the course title.  In the case of the second query these tables would again 
> be joined to the CoursesTaken table in the outer query, but you'd also join 
> the Courses table to the CoursesTaken table in the subquery and return the 
> course title rather than the CourseID as RetrainingCourseTaken column.
> 
> Ken Sheridan
> Stafford, England 
> 
> "Cydney" wrote:
> 
> > Hi, I have a table that lists courses an employee has taken. I also have a 
> > list of courses, when then expire and what their retraining course should be. 
> > Now I need to determine if the employee has taken not only the original 
> > course, but the retrained course when they're on separate lines.
> > 
> > So.. if he's taken course 123 which expires in 12 months. Then he takes 
> > course 124. It shows in the list of courses that he's taken that 124 was also 
> > completed. However, my flag just determines that 123 is expired. I need that 
> > flag to not show if 124 has been taken.
> > 
> > Hope that's a complete enough explanation...
> > 
> > -- 
> > THX cs
> 
0
Utf
2/26/2008 12:19:02 AM
Ken, I hope you're still available to help me on this today.. I spent all day 
yesterday trying out different scenarios and thought I had it figured out. 
Then I did another test and ...it (my theories) broke down... 

Here's my latest that is a slight twist on what I asked you for before.

(My Code below) CT1 has all the courses the employee has taken. CT2 has the 
list of all the REQUIRED courses for the appropriate WC (worker category) the 
employee falls in. What I want to see is all the courses that he is required 
to take within all the courses he HAS taken.

Basically I should see:

WC   Empl   ReqCourse  CourseTaken 

AB    Joe     123             123
AB    Joe     124    
AB    Joe     125             125

I want to know that Joe hasn't taken his 124 course yet.

Later, I'll then want to add in the retraining course and have the decision 
made of IF Joe has taken 123 and also 125 (the retraining), then he shouldn't 
be flagged. Also, if he hasn't taken 124 OR 126 (which he couldn't have taken 
without the 124 prerequisite) then he should be flagged. 

Then.. the final step is, if he's taken the prerequisite course, and the 
retraining course, but the retraining has expired, Joe needs to have a red 
flag. Otherwise, all is well.

WC   Empl   ReqCourse  CourseTaken   RetrainCourse  DateTaken   Expires

AB    Joe     123             123                125
AB    Joe     124                                  126
AB    Joe     125             125

Here's the code I have so far.. and it isn't working correctly.

SELECT WC, Empl, CourseTkn 
FROM tmpEmplCoursesTaken AS CT1
WHERE (((Exists (SELECT  WC, ReqCourse
FROM qCourses as CT2
WHERE CT1.WC=CT2.WC))=False));


I am in deepest gratitude for your help, Ken.
-- 
THX cs


"Ken Sheridan" wrote:

> If I understand you correctly you want to return rows where no other row 
> exists for that employee where the course taken is the retaining course 
> specified in the first row.  The solution to this type of problem is to 
> restrict the rows returned by a query by means of a correlated subquery.  
> Lets assume your table is called CoursesTaken and has, amongst others, 
> columns EmployeeID, CourseTakenID, RetrainingCourseID.  The first column 
> would reference the primary key of an Employees table and the other two 
> columns the primary key of  a Courses table.  The CoursesTaken table in fact 
> models a many-to-many relationship type between the other two.  So a query 
> would be like this:
> 
> SELECT *
> FROM CoursesTaken AS CT1
> WHERE NOT EXISTS
>     (SELECT *
>      FROM CoursesTaken AS CT2
>      WHERE CT2.EmployeeID = CT1.EmployeeID
>      AND CT2.CourseTakenID = CT1.RetrainingCourseID);
> 
> The above would return just those rows where an employee has not yet taken 
> the specified retraining course.  An alternative solution would be to include 
> the subquery in the outer query's SELECT clause.  This would return rows 
> showing all courses taken, but with an extra column showing the specified 
> retraining course only if taken; otherwise the column would be null:
> 
> SELECT EmployeeID, CourseTakenID,
>     (SELECT RetainingCourseID
>      FROM CoursesTaken AS CT2
>      WHERE CT2.EmployeeID = CT1.EmployeeID
>      AND CT2.CourseTakenID = CT1.RetrainingCourseID)
> AS RetrainingCourseTaken
> FROM CoursesTaken AS CT1;
> 
> The above queries use only the one table, but in reality of course (no pun 
> intended!) you'd join the Employees and Courses tables to the CoursesTaken 
> table in the outer query of the first query to show the employee's name and 
> the course title.  In the case of the second query these tables would again 
> be joined to the CoursesTaken table in the outer query, but you'd also join 
> the Courses table to the CoursesTaken table in the subquery and return the 
> course title rather than the CourseID as RetrainingCourseTaken column.
> 
> Ken Sheridan
> Stafford, England 
> 
> "Cydney" wrote:
> 
> > Hi, I have a table that lists courses an employee has taken. I also have a 
> > list of courses, when then expire and what their retraining course should be. 
> > Now I need to determine if the employee has taken not only the original 
> > course, but the retrained course when they're on separate lines.
> > 
> > So.. if he's taken course 123 which expires in 12 months. Then he takes 
> > course 124. It shows in the list of courses that he's taken that 124 was also 
> > completed. However, my flag just determines that 123 is expired. I need that 
> > flag to not show if 124 has been taken.
> > 
> > Hope that's a complete enough explanation...
> > 
> > -- 
> > THX cs
> 
0
Utf
2/26/2008 6:17:01 PM
Reply:

Similar Artilces:

Timer for Queries?
Does anyone know of a macro or add-on that I could use as a simple timer for queries? I don't like to use the CPU time in the Task Manager because of it's inaccuracy when not receiving full CPU usage. THanks for any suggestions -- cmungs Exactly what are you trying to accomplish? Are you trying to cause a query to run automatically every so often? If so, you will need to use the timer event on a form to do that. -- Lynn Trapp Microsoft MVP (Access) www.ltcomputerdesigns.com "cmungs" <cmungs@discussions.microsoft.com> wrote in message news:88EC7019-045F-4EF...

Erratic results from query criteria
I am getting different results from running the same query with the same selections. One moment it is all behaving as expected, the next it has gone haywire. (I have done what appears to me to be EXACTLY what I have done in another database, where it works perfectly every single time.) In a query I have, amongst others, the following fields: Category SubCategory Company I want to be able to select any OR ALL of the relevant fields. I have the following criteria: Like "*"&[Type Category otherwise leave blank for ALL]&"*" Like "*"&a...

Update Query ?
Is there a way to 1) Assign events when adding in data thru an update query for example if you append a bunch of data into a table could you then do some kind of an update query to say if there is an initial event and no others tag this one Renewal 1 etc.. the only real data you have to go on would be Customer A and the total amt .. the event, renewal event and the delta would all need to be added in example: Say Customer A comes in with an initial deal then Customer A renews their deal So, the data would look like when you're done.: Year Custo...

design query match anywhere?
In the design query I want to match the letters "ABC" anywhere in the column 'description'. I could not get instr to work by using: InStr(description, "ABC")) > 0 How else can I match ABC (upper and lowercase) to anywhere in my 'description' column? Thanks! Are you saying you put that InStr bit as a criteria under your Description field in the query designer? Try putting Like "*ABC*" as the criteria instead. Alternatively, you could add a computed field to the query InStr([Description, "ABC") and then put >0 as the ...

Unexpected Error- Running Advance Find Query
I am getting a message that says "Unexpected Error An Error has occurred" when I am running an advanced find query on two custom entities. It seems to be when I have certain custom fields included in my view that the query errors out. Any help on this would be greatly appreciated. Thanks so much. Just wanted to add that I seem to get errors when there is a 0.00 amount in these fields... "TJ" wrote: > I am getting a message that says "Unexpected Error An Error has occurred" > when I am running an advanced find query on two custom entities. It se...

pass through query
If a combobox is populated by a pass-through query, does it requery every time the form is closed and reopened? Thanks, Sam Yes. John Spencer Access MVP 2002-2005, 2007-2010 The Hilltop Institute University of Maryland Baltimore County Sam wrote: > If a combobox is populated by a pass-through query, does it requery every > time the form is closed and reopened? > Thanks, > Sam ...

a count field in a query?
Hello, I have a query in which I would like to create a field which increments by 1 for each record selected, so if there are 10 records selected by the query, this column would show numbers 1 to 10. Ideally I would like to have some text in front of each number, say invoice1, invoice2 etc. From a previous posting I realise that this is frowned upon but it would be the simplest solution for my problem! How can I do this? Thanks Geoff On Mon, 03 Dec 2007 08:54:00 +0000, Geoff Cox <<>> wrote: >Hello, > >I have a query in which I would like to create a field which >...

How does Outlook determine if a POP3 message is downloaded or not?
Hi, I use Outlook2007 with POP3 and I use the option "Leave a copy of message on the server." Why outlook? Calendaring support. No other tool comes close (or I am not aware) Why POP3? mail server is not exchange Why "Leave a copy of message on Server"? 1. Server's backed up, 2. Can read mails while on the move However, there's one problem. When I move machines and open the PST on the new machine, outlook fetches the entire inbox creating a duplicate of the message within the PST. My problem is not this behaviour because I understand that Outlook does not have the ...

Birthday query for many children in one record
I have a database for the church, it has one main flat table only. Each record for the parents have field for child1 name, child1birthday, child2 name, child2birthday, child3 name, child3birthday - up to 5 children. I am having difficulty trying to get a report to list the birthdays of the children like this parent name, child 1 name, child 1 birthday month etc. so you get something like this:- Parent John Smith, child Mary Smith January 3 Parent Fred Jones, child Bert Jones March 4 Parent John Smith, child Jane Smith March 6 Parent Harry Brown, child Jane Brown March 6 Parent Bert Taylor,...

Saving Username and Pass with Web Queries
I am pulling data from a website that requires you to provide a usernam and password everytime you visit the site. Excel has cachin capabilities, but everytime you close excel and try and open up th spreadsheet again, it can't login. What is the fix for this? Thanks, Hend -- Message posted from http://www.ExcelForum.com Bump! --- Message posted from http://www.ExcelForum.com/ ...

Unresponsive Query Wizard
Hi there, I have an Excel 2003 user who is using a spreadsheet that pulls data from our SQL server. When he opens it and refreshes the data it is fine, it pulls the current data, but when he tries to edit the query, the Query Wizard does not appear, he can see it on the task bar, but when he switches focus using task manager everything is greyed out and nothing works. I have tested the file from my computer and it is fine, which suggests a problem with his machine or installation. Does anyone have any ideas? Cheers, Steve Dooza wrote: > Hi there, > I have an Excel 2003 user who...

Another simple query
Dear all, I have a table that contains first names and last names in different fields. Is there any way to write a query that will give as a result the first name and last name in the same field? I hope this makes sense. Thanks in advance! SELECT [last_name_field] & ", " & [first_name_field] AS whole_name FROM [your_name_table] Change the field and table names to whatever your actual fields and tables are. Cheers, Jason Lepack On Apr 23, 9:47 am, Homer <peter.a.r...@googlemail.com> wrote: > Dear all, > > I have a table that contains first names an...

Query query
I am trying to create a new field in which it shows the sum total of 10 fields (Charge Time, Charge Time 2, Charge Time 3, etc.); what is the easiest way to do this? -- Joe NewFieldName: [Charge Time] + [Charge Time 2] + [Charge Time 3] .... etc -- Good Luck BS"D "joet5402" wrote: > I am trying to create a new field in which it shows the sum total of 10 > fields (Charge Time, Charge Time 2, Charge Time 3, etc.); what is the easiest > way to do this? > -- > Joe I tried this, and it doesn't work. Is there something I'm forgetting? -- Joe ...

group by query trouble
I'm trying to run a query that counts the number of people with hemoglobin of type SS, type SC, and then all others. There are about 12 different kinds of types. Basically I want a count for SS, a count for SC, and then a count that totals all the others into one count. Hopefully that makes sense. I'm using group by for the SS and SC which works great, but I'm not sure how to tell it to add up the others. I'm not a big fan of nested IIf statements, but this should work after you put in the proper field and table names: SELECT IIf([Hemoglobin]="SC","SC&...

To Query or not to Query??
Hello all - I'm a newbe to Access but have made great progress. I'm using Acess 2003. The db is up and running prefectly. Now I need to tackle the reporting. I have seen posts about reports and queries and am a little confused. Do I need to create a query to run my reports off of? I have a tabbed subform in the main form. There are seven tabs breaking up all the services we provide. Like "Promo Items", "Leads", "Client Printed Material","Internal Print Material" and so on. The main form has the User, Branch and Marketing Rep. I need to...

Dynamic Query
Hi! I am trying to dynamically modify my pass-through query containing a procedure call with 2 parameters. When I run my access app, I get this error: "Object or provider is not capable of performing reuqested operation." Below is my access code: Dim varItem As Variant Dim strSQL As String Dim cat As ADOX.Catalog Dim cmd As ADODB.Command Dim strMyDate As String, dtMyDate As Date dtMyDate = CDate([Forms]![ySalesHistory]![Start Date]) strMyDate = Format(dtMyDate, "yyyymmdd") strSQL = "procCustomerSalesandPayments '" & s...

Query in Access 2007
I have linked via ODBC tables from another database. I have created a query to pull in two columns of information from the two tables in the query. I would like to add an extra column that is only created when the query is run, to dynamically number each row incrementally, depending on how many rows the query returns. If it returns 10 rows, then the first column should be numbered 1 to 10, if it returns 357 rows, then the rows should automatically incrementally number each from from 1 to 357. Try this but substitute your table and field names. Prim is your primary key. This can o...

Linking tables in a query
I have a database that contains information on a certain number of individuals during different session. Table 1 'tbl_Tracking_Form1' has information on sessions 2,4 and 6. Table 2 'tbl_Tracking_Form2' has information on sessions 1,3 and 5. Table 3 'tbl_General_Info' has demographic information on all the individuals (those who will eventually attentd sessions 1,2,3,5,5 and 6). I need to create two reports. One (Report1) should display all the information on the individuals during session 2, 4 and 6 and another(Report2) that displays all the information on the i...

query question
I want to be able to run a query i guess to populate the additional information fields in the customer properties. I sell certain items that have warranties and serial numbers and would like the product name (or discription) to display on the first field the date of purchase on the second feild, and the serial # on the third field. I would like to be able to run this query i guess on a weekly bases and be able to run t for all of my past sales as well. Victor ...

web query query!
Hi All I've developed a worksheet that retrieves external data from a web page (stocks & shares info). At the moment I display the data at a certain cell in the worksheet so other cells in the sheet can calculate values of my shares. As I don't need the all the external data to be viewed (I only need one column of values), is there a way to extract the data I need from the web query without displaying it all in the worksheet? Thanks in advance Dave ...

MS Query: WHERE vs HAVING
When I use MS Query to bring data from an external source, Query usually translates my criteria into a HAVING statement, which results in my criteria being included in the GROUP BY statement -- which I do not want. I then have to manually change the HAVING to a WHERE, move the criteria up above the GROUP BY and edit the GROUP BY. I don't like to be bothered to do this, and have trouble explaining this technique to others. Is there a way to make MS Query default to WHERE instead of HAVING? Is there a way to influence which method is used for a particulary query? Thank you. ...

Is there a way to turn off the prompts of a make table query?
I merely want to update the table to be used as an export to Excel using TransferSpreadsheet. Each time it prompts for deleting old records and adding new records. Is there a was to turn off the prompts? Bottom line - I want to create an Macro to export the output of a query to an Excel spreadsheet. BobC, DoCmd.SetWarnings False 'Off Your TransferSpreadsheet line here DoCmd.SetWarnings True 'On -- Gina Whipp "I feel I have been denied critical, need to know, information!" - Tremors II http://www.regina-whipp.com/index_files/TipList.htm "...

what is query
I have two table. Table1 : ID# name_of_staff Table2 : File_No (Auto number) Document_Name Forwarded_To The above two table have to connect together. This is a filing system for my day today papers which is each one is going to files after process. I will put File_No as I get from the secnd table on the respective papers to file. What is data type of ID# and File_No Kutty Unless the two tables have a common field they share, how will Access know which records belong together? I'm not seeing a shared field ... ...

Clear form after append query
Good day all, I have a question and I'm sure there is a way to do this but can't find any examples on how. What I have is a form controlled by a table tblwaitinglist. I have a an append query that appends the records to a tblinitialdata. What I would like to do id once the append query runs, the record is deleted from the tblwaitinglist. So after I hit the append button, the query runs record appends and the form clears. I hope this makes sense and any help would be greatly appreciated. VR, Red -- Message posted via http://www.accessmonster.com You say that you execute an Ap...

Determine if workbook is open
Does Excel 2007 have any functions or means of determining if a workbook is currently opened or being used by another user?? For example, if a workbook file is already open and a user named Joe Smith has it open, I would like to display a message box message like "User joesmith is currently using workbook!". Thank you! Perhaps: http://www.vbaexpress.com/kb/getarticle.php?kb_id=468 -- Gary''s Student - gsnu201001 "Robert Crandal" wrote: > Does Excel 2007 have any functions or means of determining > if a workbook is currently opened...