We have a database that we use for tracking data and sending communications on a shared network drive. Recently we’ve had to incorporate a process to prefill out forms for an M1 Visa Application that has fields we do not track by in our tables but can be calculated based on the information we do track.
I have created several SQL Queries that pull data from two tables to produce certain field formats required on the application. All the queries pull from the same two tables. When I have the database on my desktop, it functions incredibly. However, when I put on the shared network drive for all users to access, the new functions I created take forever to produce results. The database works normally for everything except when utilizing the new SQL Queries I created.
I read online that the database is likely slowing down because it’s having to run 3-4 queries before adding the produced results to the form. I am asking today how to combine my multiple SQL Queries into one, to hopefully reduce the wait time.
I am not familiar with SQL or database coding really. Everything in our system works because I spend hours reading and using trial/error to produce the results needed. Posting the SQL code for the main two queries I need to combine below in hopes that someone can help me figure out how to get it to work. I've spent the past two days googling and reading, only to come up with I may need statements like CASE, UNION ALL, or something of that sort. But I am at a complete loss. Please help! Thank you!!
Query 1
SELECT DISTINCT Request.PermNumber, Request.Status,
Request.Class, Request.StartDate, Request.Days,
ConcatRelated("Class",
"MALTESTConfirmationInformationQry2022",
"PermNumber= " & Request.PermNumber) AS AllClasses
FROM Employee INNER JOIN Request ON Employee.PermNumber = Request.PermNumber
WHERE (((Request.Status)="Confirmed") AND ((Request.StartDate)>Date()))
ORDER BY Request.StartDate;
Query 2
SELECT Request.PermNumber, Request.Status, Sum(Request.Days) AS TotalDays
FROM Employee INNER JOIN Request ON Employee.PermNumber = Request.PermNumber
GROUP BY Request.PermNumber, Request.Status
HAVING (((Request.Status) Like "Confirmed"));
I finally got around to looking at this in more depth. Here is the final solution that should run very quickly. I have not been able to fully test it because I do not have any data examples and I have had to make a few assumptions as a result. However, any issues you might come across should be quite minor. Copy the below code into a module:
And now modify the query as shown below or just copy and paste it:
I think you will be pleasantly surprised.