Trying to create a complex query

psycoperl

Active Member
Joined
Oct 23, 2007
Messages
339
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
  2. MacOS
  3. Web
I am working on trying to write a query that will give me available sessions that have seats remaining, and cannot figure out how to write one that will give me everything I need. Any help and guidance would be most helpful

Need to obtain:
ts.tsTestSessionID, ts.tsTestSessionDateTime, number of seats available for session (tsMaxRegistration – number of students already scheduled for the session)

Where
1. the most recent tnTestCode for the studentID displayed on the form tblStudentTestNeeds (it is logged in by tnDateEntered) is in the list of tsTestTypes (a comma separated list) in tblTestSessions.
2. the number of students already scheduled is less than the tsMaxRegistration, ap.aptSession contains the tsTestSessionID and are not canceled (ap.aptCancel)


Tables:
tblTestSessions [ts] fields:
tsTestSessionID, tsTestTypes, tsTestSessionDateTime, tsMaxRegistration, tsMaxRegistrationOverride, tsRoom

tblStudentAppointments [ap] fields:
aptRecordID, aptStudentID, aptTestCode, aptSession, aptPresent, aptDateCompleted,
aptIncomplete, aptEmail, aptPrint, aptCancel, aptDateAdded, aptDateSentEmail,
aptDateSentPrinted, aptModified, ResendETicket, ResendPTicket

tblStudentTestNeeds [tn] fields:
tnRecordID, tnStudentID, tnTestCode, tnDateEntered

Form Used:
frmAppointmentScheduling
 

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)
Re: Trying to create a complex query (Parital Solution)

I have been working on this problem and have so far gotten gotten a query where I am trying to just get

The Sessions table with the count of appointments from the appointments table.

When I try to view it, I get a prompt asking for tblTestSessions.tsTestSessionsID

Why? What did I do wrong?

Code:
SELECT tblTestSessions.tsTestSessionID, tblTestSessions.tsTestTypes,
tblTestSessions.tsTestSessionDateTime, tblTestSessions.tsMaxRegistration,
tblTestSessions.tsMaxRegistrationOverride, tblTestSessions.tsRoom, 
apt.NumOfAppointments
FROM tblTestSessions 
   LEFT JOIN 
      (SELECT tblStudentAppointments.aptSession, 
    Count(tblStudentAppointments.aptRecordID) AS NumOfAppointments 
     FROM tblStudentAppointments 
     GROUP BY tblStudentAppointments.aptSession) APT 
 ON tblTestSessions.tsTestSessionsID = apt.aptSession;
 
Upvote 0
When I try to view it, I get a prompt asking for tblTestSessions.tsTestSessionsID
That usually means that it is not recognizing the field name in that table name. Make sure it exists, and you have spelled the table/field names correctly.
 
Upvote 0
That usually means that it is not recognizing the field name in that table name. Make sure it exists, and you have spelled the table/field names correctly.

Got it... I added an S in tblTestSessions.tsTestSessionsID where it should have been tblTestSessions.tsTestSessionID

thanks
 
Upvote 0

Similar threads

Forum statistics

Threads
1,224,527
Messages
6,179,357
Members
452,907
Latest member
Roland Deschain

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top