473,385 Members | 1,478 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.

Removing Duplicates / Combining Query Results

I have a database that has two tables that we are concerned with. One is for People (tblAlpha)and the other is for Appointments (tblSchedule). The designer (ages ago and unknown) designed a calendar that would use 14 queries to do some date math and link the results with tblAlpha and ultimately displayed on a form.

The schedulers like to work with month long timeframes and when I tried to add another 15 queries it locked up access.

After some fumbling around I decided to cut out the middleman on the queries and just link the two tables together and create 31 fields similar to the one below. The start date is selected by the user and stored as DStamp in the tblMainInformation.

Expand|Select|Wrap|Line Numbers
  1. Appt01: IIf([Scheduled]<=ELookUp("DStamp","tblMainInformation","[ID] = 1") And [StopDt]>=ELookUp("DStamp","tblMainInformation","[ID] = 1")=-1,[ApptComment],"")
  2. (through)
  3. Appt31: IIf([Scheduled]<=ELookUp("DStamp","tblMainInformation","[ID] = 1")+30 And [StopDt]>=ELookUp("DStamp","tblMainInformation","[ID] = 1")+30=-1,[ApptComment],"")
This runs and the table/datasheet is displayed in well under a second. The new problem is that if an individual has more than one appointment during the timeframe, they will have more than one record (right term?) on the datasheet.

It would seem to be a fairly easy procedure to have Access combine all of the records with the same specified/unique field value (i.e. SSN)…I just don’t know how to do it.

Expand|Select|Wrap|Line Numbers
  1. ............1 Aug........2 Aug
  2. John, Doe...Dental 0900
  3. John, Doe................Oil Change 0730
  4.  
  5. to
  6.  
  7. ............1 Aug........2 Aug
  8. John, Doe...Dental 0900..Oil Change 0730 
  9.  
This was posted here as well, but I don’t think it is getting answered.
http://www.access-programmers.co.uk/...78#post1370078
Aug 1 '14 #1
9 1303
zmbd
5,501 Expert Mod 4TB
I know that you've attempted to tell us the nature of the database; however, you've really not told us enough.

On the surface it sounds as if you might need a cross-tab-query; however, most likely your entire premise is flawed without an understanding of the thought process your developer used...

The problem for us is that you would have to go into great depth about the forms and each of the queries used in order for us to be able to help as it sounds like you've attempted to really alter a project at its foundation.

Instead of adding your additional queries, you might want to take a very careful look at the existing queries and determine how they were written and if they can be modified to accomplish your new goal.

OR

You might want to check out the MS Calendar project... the overview is in our insights articles here: MS Calendar Overview this is a project that ADezii developed and is kind enough to share with our membership. I highly advise reading thru this link and then searching on Bytes.com (use the search box at the top of our page (^_^) next to the orange magnifying glass button) using Adezii Calendar as key words) Adezii has answered and modified the project many times and I'm sure that if the base project doesn't meet your needs that one of the modifications will... although, next to Outlook, the basic project code is really well formed and very easy to work with!
Aug 2 '14 #2
First, let me start by thanking you for the response. I will have to download the MS Calendar at home because it is blocked from work.

Here is a breakdown of what happens:

-The user (scheduler) selects a start date and then opens the desired calendar (7 day, 14 day or 31 Day).

(Original Version)
- The queries check to see if each appointment (tblSchedule) is on each of the days. The formula is checking to see if the start date is before or equal to the start date (each subsequent formula adds a +1 to the date) and that the end date is greater than or equal to the start date.

-All the queries are then linked to the table that contains the individual’s information (tblAlpha). qryScheduleDay01 would be the start date’s appointments, qryScheduleDay02 would be the next day’s and so on.

The problem with this set up is that when more than 20 or so queries are linked like this, Access locks up.

(Modified Version)
-The two tables are linked in a query with a one to many relationship. There are 31 expressions (right term?) that check to see if any appointments are due on that day (Start Date, Start Date +1 and so on).

-While this is much much faster than the original version (which could take up to a minute to do the math and open the 14 day calendar…the modified version is just a couple of seconds) if an individual has more than one appointment during the timeframe they will be listed more than once in the results.

Because I am completely self-taught and have zero schooling or training on coding I am stuck. I’ve tried to look at “concatenate” functions to combine records that have the same specified criteria (SSN, Last name etc.) but they may as well be written in Egyptian hieroglyphics.

I suspect it would be easier to remove the tblSchedule from the query and just rewrite the following to search in there, adding a WHERE SSN matches the tblSchedSSN…but I’m dangerously close to common sense and that seldom works out.

Expand|Select|Wrap|Line Numbers
  1. Appt01: IIf([Scheduled]<=ELookUp("DStamp","tblMainInformation","[ID] = 1") And [StopDt]>=ELookUp("DStamp","tblMainInformation","[ID] = 1")=-1,[ApptComment],Null)
Aug 4 '14 #3
zmbd
5,501 Expert Mod 4TB
Just so that we can actually see how your project was working.

open the query for the "seven day" in SQL view.
Click on the [CODE/] button in the post toolbar and then cut and paste your SQL script between the [code] [/code] tags.
It would good of you to format the SQL ( > Before Posting (VBA or SQL) Code ) but for a first time post we give a lot of wiggle room (^_^)

Let us see if there are not some ways to stream-line what your developer was doing....

Also, if you use the [ADVANCED] button at the bottom of the posting box, you can upload a screen-shot of your form for the "seven-day" Now we do understand sensitive data so if you need to, take it into paint or the like and erase the sensitive parts...

On a side note, and this would need its own thread for depth/detail: you mention SSN... it is Rarely a good idea to have these in plain text. At least an MD5-hash should be used and the actuall SSN never stored. If you do have to store these then either use the file encryption provided within ACC or look into the encryption methods discussed here at bytes
Aug 4 '14 #4
Attached are the screen shots of the daily query and how they are associated with the tblAlphaList

Below is the SQL code
Expand|Select|Wrap|Line Numbers
  1. SELECT 
  2.    [Last] & ", " & [First] & " " & [MI] & " " & [Suffix] 
  3.       AS FullName
  4.    , tblAlphaList.Office
  5.    , tblAlphaList.Status, tblAlphaList.Shift
  6.    , tblAlphaList.Shift12, tblAlphaList.TrainingCheck03
  7.    , tblAlphaList.TrainingCheck04, tblAlphaList.TrainingCheck05
  8.    , tblAlphaList.TrainingCheck06, tblAlphaList.TrainingCheck07
  9.    , tblAlphaList.SSN, tblAlphaList.Last
  10.    , tblAlphaList.First, tblAlphaList.MI
  11.    , tblAlphaList.Suffix, tblAlphaList.LoadCrewNumber
  12.    , tblAlphaList.LoadTeamPosition, tblAlphaList.SkillLevel
  13.    , tblAlphaList.Rank
  14.    , [qryScheduleDay01]![Apptcomment] 
  15.       AS Appt1
  16.    , [qryScheduleDay02]![Apptcomment] 
  17.       AS Appt2
  18.    , [qryScheduleDay03]![Apptcomment] 
  19.       AS Appt3
  20.    , [qryScheduleDay04]![Apptcomment] 
  21.       AS Appt4
  22.    , [qryScheduleDay05]![Apptcomment] 
  23.       AS Appt5
  24.    , [qryScheduleDay06]![Apptcomment] 
  25.       AS Appt6, 
  26.    , [qryScheduleDay07]![Apptcomment] 
  27.       AS Appt7
  28.    , [qryScheduleDay08]![Apptcomment] 
  29.       AS Appt8
  30.    , [qryScheduleDay09]![Apptcomment] 
  31.       AS Appt9
  32.    , [qryScheduleDay10]![Apptcomment] 
  33.       AS Appt10
  34.    , [qryScheduleDay11]![Apptcomment] 
  35.       AS Appt11
  36.    , [qryScheduleDay12]![Apptcomment] 
  37.       AS Appt12
  38.    , [qryScheduleDay13]![Apptcomment] 
  39.       AS Appt13
  40.    , [qryScheduleDay14]![Apptcomment] 
  41.       AS Appt14
  42. FROM (((((((((((((
  43.    tblAlphaList LEFT JOIN qryScheduleDay01 
  44.       ON tblAlphaList.SSN = qryScheduleDay01.[tblSchedSSN]) 
  45.       LEFT JOIN qryScheduleDay03 
  46.          ON tblAlphaList.SSN = qryScheduleDay03.[tblSchedSSN]) 
  47.          LEFT JOIN qryScheduleDay02 
  48.             ON tblAlphaList.SSN = qryScheduleDay02.[tblSchedSSN]) 
  49.             LEFT JOIN qryScheduleDay04 
  50.                ON tblAlphaList.SSN = qryScheduleDay04.[tblSchedSSN]) 
  51.                LEFT JOIN qryScheduleDay05 
  52.                   ON tblAlphaList.SSN = qryScheduleDay05.[tblSchedSSN]) 
  53.                   LEFT JOIN qryScheduleDay06 
  54.                      ON tblAlphaList.SSN = qryScheduleDay06.[tblSchedSSN]) 
  55.                      LEFT JOIN qryScheduleDay07 
  56.                         ON tblAlphaList.SSN = qryScheduleDay07.[tblSchedSSN]) 
  57.                         LEFT JOIN qryScheduleDay08 
  58.                            ON tblAlphaList.SSN = qryScheduleDay08.[tblSchedSSN]) 
  59.                            LEFT JOIN qryScheduleDay09 
  60.                               ON tblAlphaList.SSN = qryScheduleDay09.[tblSchedSSN]) 
  61.                               LEFT JOIN qryScheduleDay10 
  62.                                  ON tblAlphaList.SSN = qryScheduleDay10.[tblSchedSSN]) 
  63.                                  LEFT JOIN qryScheduleDay11 
  64.                                     ON tblAlphaList.SSN = qryScheduleDay11.[tblSchedSSN]) 
  65.                                     LEFT JOIN qryScheduleDay12 
  66.                                        ON tblAlphaList.SSN = qryScheduleDay12.[tblSchedSSN]) 
  67.                                        LEFT JOIN qryScheduleDay13 
  68.                                           ON tblAlphaList.SSN = qryScheduleDay13.[tblSchedSSN]) 
  69.                                              LEFT JOIN qryScheduleDay14 
  70.                                                 ON tblAlphaList.SSN = qryScheduleDay14.[tblSchedSSN]
  71. WHERE 
  72.    (((tblAlphaList.Status)="Assigned"))
  73. ORDER BY 
  74.    tblAlphaList.Last
  75.    , tblAlphaList.First
  76.    , tblAlphaList.MI;
If it would help, the database is currently loaded with fake names and SSNs so I can upload that as well without violating any PII regulations.



Attached Images
File Type: jpg Daily Queries to Alpha List 14 Day.jpg (55.5 KB, 245 views)
File Type: jpg Daily Query Example.jpg (47.0 KB, 248 views)
Aug 5 '14 #5
zmbd
5,501 Expert Mod 4TB
It appears that your database is not normalized hence all of the extra queries and hardship.

How is the data displayed to the users?
Aug 5 '14 #6
Attached are screenshots of the reports (7 and 30 day), both showing the duplication



Attached Images
File Type: jpg Report Example (30 Day).jpg (78.7 KB, 249 views)
File Type: jpg Report Example (7 Day).jpg (68.0 KB, 205 views)
Aug 7 '14 #7
zmbd
5,501 Expert Mod 4TB
OK, the pictures are a tad small; however I think I see what you are talking about... the purple fields are one assignment for the individual, and the row below that has that same individual's name, and the next assignment in that row instead of merged with the row above.
The columns have the dates...
Check out Allen Browne's Crosstab query... Allen Brown CrossTab Query

In the meantime... it will take awhile to digest.
Aug 7 '14 #8
Thank you again, I'll look at Mr. Brown's website. Hopefully it will make sense =D
Aug 7 '14 #9
Would it be possible to use the GROUP_CONCAT function with the following query or maybe a DISTINCT clause?

This is the query I was working with that directly links the personnel and appointments tables rather than have a query for each day like the previous post.

Expand|Select|Wrap|Line Numbers
  1. SELECT tblAlphaList.Last, tblAlphaList.First, tblAlphaList.Status, IIf([Scheduled]<=ELookUp("DStamp","tblMainInformation","[ID] = 1") And [StopDt]>=ELookUp("DStamp","tblMainInformation","[ID] = 1")=-1,[ApptComment],"") AS Appt01, IIf([Scheduled]<=ELookUp("DStamp","tblMainInformation","[ID] = 1")+1 And [StopDt]>=ELookUp("DStamp","tblMainInformation","[ID] = 1")+1=-1,[ApptComment],"") AS Appt02, IIf([Scheduled]<=ELookUp("DStamp","tblMainInformation","[ID] = 1")+2 And [StopDt]>=ELookUp("DStamp","tblMainInformation","[ID] = 1")+2=-1,[ApptComment],"") AS Appt03, IIf([Scheduled]<=ELookUp("DStamp","tblMainInformation","[ID] = 1")+3 And [StopDt]>=ELookUp("DStamp","tblMainInformation","[ID] = 1")+3=-1,[ApptComment],"") AS Appt04, IIf([Scheduled]<=ELookUp("DStamp","tblMainInformation","[ID] = 1")+4 And [StopDt]>=ELookUp("DStamp","tblMainInformation","[ID] = 1")+4=-1,[ApptComment],"") AS Appt05, IIf([Scheduled]<=ELookUp("DStamp","tblMainInformation","[ID] = 1")+5 And [StopDt]>=ELookUp("DStamp","tblMainInformation","[ID] = 1")+5=-1,[ApptComment],"") AS Appt06, IIf([Scheduled]<=ELookUp("DStamp","tblMainInformation","[ID] = 1")+6 And [StopDt]>=ELookUp("DStamp","tblMainInformation","[ID] = 1")+6=-1,[ApptComment],"") AS Appt07
  2. FROM tblAlphaList LEFT JOIN tblSchedule ON tblAlphaList.SSN = tblSchedule.tblSchedSSN
  3. GROUP BY tblAlphaList.Last, tblAlphaList.First, tblAlphaList.Status, IIf([Scheduled]<=ELookUp("DStamp","tblMainInformation","[ID] = 1") And [StopDt]>=ELookUp("DStamp","tblMainInformation","[ID] = 1")=-1,[ApptComment],""), IIf([Scheduled]<=ELookUp("DStamp","tblMainInformation","[ID] = 1")+1 And [StopDt]>=ELookUp("DStamp","tblMainInformation","[ID] = 1")+1=-1,[ApptComment],""), IIf([Scheduled]<=ELookUp("DStamp","tblMainInformation","[ID] = 1")+2 And [StopDt]>=ELookUp("DStamp","tblMainInformation","[ID] = 1")+2=-1,[ApptComment],""), IIf([Scheduled]<=ELookUp("DStamp","tblMainInformation","[ID] = 1")+3 And [StopDt]>=ELookUp("DStamp","tblMainInformation","[ID] = 1")+3=-1,[ApptComment],""), IIf([Scheduled]<=ELookUp("DStamp","tblMainInformation","[ID] = 1")+4 And [StopDt]>=ELookUp("DStamp","tblMainInformation","[ID] = 1")+4=-1,[ApptComment],""), IIf([Scheduled]<=ELookUp("DStamp","tblMainInformation","[ID] = 1")+5 And [StopDt]>=ELookUp("DStamp","tblMainInformation","[ID] = 1")+5=-1,[ApptComment],""), IIf([Scheduled]<=ELookUp("DStamp","tblMainInformation","[ID] = 1")+6 And [StopDt]>=ELookUp("DStamp","tblMainInformation","[ID] = 1")+6=-1,[ApptComment],"")
  4. HAVING (((tblAlphaList.Status)="Assigned"))
  5. ORDER BY tblAlphaList.Last, tblAlphaList.First;
Aug 8 '14 #10

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

Similar topics

1
by: Guy Erez | last post by:
Hi, I'm running queries with MySql 4.0.17 that return thousands of records. Because I need to present them in GUI, I returieve the results in chunks using LIMIT, for example - get first 100,...
0
by: Rob | last post by:
I doubt this is the best way to do it, but what I came up with was to hide the XML in an HTML Comment then edit the file deleting the HTML stuff and keep the XML results. If anyone has a better...
16
by: tyrfboard | last post by:
I've been searching for awhile now on how to remove duplicates from a table within an Access db and have found plenty of articles on finding or deleting duplicates. All I want to do is remove them...
9
by: Kelii | last post by:
I've been trying to get this piece to work for a few hours, but have given up. I hope someone out there can help, I think the issue is relatively straightforward, but being a novice, I'm stumped....
2
by: Himmel | last post by:
Hello! The reference database I currently use runs queries that pull data from hundreds of tables in order to create user-friendly form view. The problem is that these queries can take upwards of...
1
by: igor221189 | last post by:
Hello everyone. I have Access 2000 database which holds student records in the school.It stores subject grades for each student.In the 'Student Grade Form', I would like to search student surname...
5
by: jmar93 | last post by:
Hi, I'm using Access 2007 and am trying to use a query as a recordsource for a form. The query is bound to a combo box that I will use to select a customer that currently has orders in the...
3
by: Ken Fine | last post by:
This is a question that someone familiar with ASP.NET and ADO.NET DataSets and DataTables should be able to answer fairly easily. The basic question is how I can efficiently match data from one...
1
by: mcfly1204 | last post by:
I am generating an XML document using C#, and I have a question on how to populate the value of a particular object with the corresponding value from a SQL query. For example, if I have a query...
1
by: Dave Mallett | last post by:
very new to Access. Trying to export query results via macro and transfertext, but keep getting error message stating "Microsoft Jet Engine cannot find the object 'HRQ-DM_Prd1_qtr.txt'. Make sure...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: 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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

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.