473,385 Members | 2,029 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Query Question for Appointments

158 100+
Good day all,

I use a query to pull-out records that haven't yet come to past from my Appointment table.

I have a potential to have a meeting with four groups of people that are kept in different tables:

TenantsT
SuppliersT
ContactsT
EmployeesT

I am somewhat able to pull out the records from TenantsT and employeesT with the current statement:
Expand|Select|Wrap|Line Numbers
  1. SELECT AppointmentT.AppointmentID,
  2.        AppointmentT.AppActive,
  3.        AppointmentT.AppDate,
  4.        AppointmentT.AppTimeFrom,
  5.        AppointmentT.AppTimeTo,
  6.        IIf(IsNull([AppointmentT].[EmployeeID]),[AppointmentT].[TenantID] & [TenantsT].[firstName] & " " & [TenantsT].[LastName],[employeesT].[FirstName] & " " & [EmployeesT].[LastName]) AS [With],
  7.        AppointmentT.IamID
  8.  
  9. FROM   TenantsT RIGHT JOIN (SuppliersT RIGHT JOIN (ContactsT RIGHT JOIN (EmployeesT RIGHT JOIN AppointmentT ON (EmployeesT.EmployeeID = AppointmentT.EmployeeID) AND (EmployeesT.EmployeeID = AppointmentT.EmployeeID)) ON ContactsT.ContactID = AppointmentT.ContactID) ON SuppliersT.SupplierID = AppointmentT.SupplierID) ON TenantsT.TenantID = AppointmentT.TenantID
  10. WHERE (((AppointmentT.AppActive)=-1) AND ((AppointmentT.IamID)=[TempVars]![CurrentUserID]));
I would like to be able to also pull out SuppliersT and ContactsT.

The challenge that I have is the null values and the iif statement.

simply described:

Do I have a meeting with a tenant OR supplier OR contact OR employee? or any combination thereof? Or Do I have a meeting with a Tenant AND a Supplier And an employee but not with a Contact? or any combination thereof?

The combination of people involved in a meeting can be quite easy in real life if you just say it: "Yes I have a meeting today with a Tenant and there will be a Supplier that will come over with an Employee and a Contact in order to do an estimate on a job."

Or

"Today I only have a meeting with two Employees.

not sure if I am phrasing this right or clear enough. please let me know and if you have an idea on how to write the statement. thanks.
Mar 10 '10 #1
5 1331
NeoPa
32,556 Expert Mod 16PB
Well, it seems AppointmentT is the fundamental table you need. If you connect all the others into it with LEFT JOINS then all appointments will be included, and so will all the other items if, and only if, they exist.

It seems as simple as that, but maybe I'm missing something.
Mar 10 '10 #2
jaad
158 100+
Yes you are right this is how I would do it if I was only looking at the query result. What I should have said is how can I "concatanate" every result into one field.?

You see I have an appointment form on my main page that shows all current appointment that have not yet come to past. If I simply use the foreign key of the other tables then I get multiple records pulled out for one appointment. I am a tad constricted with space on my main page and trying to keep it as compact and as simple as I can with only one line showing all the people that I have appointment with in one record. Does this make more sense?
Mar 10 '10 #3
NeoPa
32,556 Expert Mod 16PB
Now you're confusing me Jaad. Do you mean field or record? It doesn't mean the same thing. In fact it is entirely different.

I see no reason why you would have the problem you describe in the scenario I outlined. Perhaps you could explain more clearly. Be especially sure to use the correct terms if possible. Using the wrong term is a recipe for confusion.
Mar 10 '10 #4
jaad
158 100+
i meant field. a control or more precisely a combox. concatenate all that I have appointment with into a single field on the same record. if you look at the statement on the first like of code you will see that I can show either employees and tenants or both or a single tenant along or a single employee alone. I would like to ad contacts and suppliers to that statement
Mar 11 '10 #5
NeoPa
32,556 Expert Mod 16PB
Check out Using "&" and "+" in WHERE Clause.

You'll need to replace line #6 with something like :
Expand|Select|Wrap|Line Numbers
  1.        Mid((', ' + ((EmployeesT.FirstName + ' ') & EmployeesT.FirstName)) &
  2.            (', ' + ((TenantsT.FirstName + ' ') & TenantsT.FirstName)) &
  3.            (', ' + ((SuppliersT.FirstName + ' ') & SuppliersT.FirstName)) &
  4.            (', ' + ((ContactsT.FirstName + ' ') & ContactsT.FirstName)),3,999) AS [With],
Mar 11 '10 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

14
by: deko | last post by:
This runs, but does not narrow to current week. suggestions appreciated! SELECT lngEid, dtmApptDate, Subject, Appt_ID FROM qry002 WHERE (dtmApptDate BETWEEN DateAdd("d",-weekday()+2,) And...
7
by: Dave Hopper | last post by:
Hi I posted a question recently regarding problems I am having getting a value from a list box to use in a query. I got a lot of help, for which I thank you and it's nearly working! But I need...
2
by: ormy28 | last post by:
I really need some help with the following problem if anyone would be willing. I need a list box to list the opposite of what appears in a query. Heres the details: My database is for a...
3
by: Lea | last post by:
Having a problem with a query within a table for appointment schedules. In this table tblMeetingInfo are two fields, StartDate and EndDate. The date information is entered into each of these...
3
by: Smriti Dev | last post by:
Hi There, I'm creating a form based on query and I want the appointments to be ordered from top to bottom with the top appointments being closest to the currrent date. How can i set this up in...
2
by: Keith Robinson | last post by:
Hi I have a table of appointments, how could I create a query to show the appointments for the week ahead. Thanks Keith
3
by: kkleung89 | last post by:
I have a particular query I need to write, but I'm not quite sure how to do it. Basically, there's a table of appointments, which has a date and a PetID, which links it to a pet table, which has a...
1
by: keri | last post by:
I would like to have a combo box on a form that shows the results of a query, however the query is variable and i am unsure how to do this. I have NO knowledge of code so very basc instructions...
6
by: Jim Mandala | last post by:
Using MS Access 2003 with SQL Server 2005 as a backend: I am trying to automatically check for collisions in a table of appointments with an appointment currenlty being saved from the form...
11
by: hedges98 | last post by:
The thread title probably isn't very clear but I can't think how to word my problem properly. Here goes: I have a form that has textboxes for users to enter information for first appointments and...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.