How To Avoid Duplicates In Append Query
Jun 13, 2005
Hi all,
I have an append query that I run daily and want to append only records with
different OrderID.
------------------------------------------------------------------------
INSERT INTO tblConfirmSchedule ( OrderID, JobCode, JobDate, Status, [Home#],
[Work #], Ext, [Other#], Ext2 )
SELECT Orders.OrderID, [Schedule Info].JobCode, JobSchedule.JobDate,
JobSchedule.Status, CustNew.[Home#], CustNew.[Work #], CustNew.Ext,
CustNew.[Other#], CustNew.Ext2
FROM (CustNew INNER JOIN Orders ON CustNew.CustomerID=Orders.CustomerID)
INNER JOIN ([Schedule Info] INNER JOIN JobSchedule ON [Schedule
Info].JobCode=JobSchedule.Scheduled) ON Orders.OrderID=[Schedule Info].OrderID
WHERE (((JobSchedule.JobDate)>Now()+3) And
((JobSchedule.Status)="Scheduled"));
--------------------------------------------------------------------------
Any ideas?
Thanks in advance,
Emilio
View Replies
ADVERTISEMENT
Nov 28, 2005
2 tables in an Access database
tblPurchases: columns: Index (PK-autonumber)| Store| Product| Cost
data: 1| Staples | Tape | $0.89
2| Staples | Paper | $4.50
3| OfficeMax | Markers | $3.50
4| OfficeMax | Paper | $4.75
5| OfficeMax | Pens | $1.98
tblInfo: columns: Index (PK-autonumber) | Store | Product
The data in the access database tblInfo.Store is queried from tblPurchases.
Here is the query for the rowin my database design view:
SELECT DISTINCT tblPurchases.Index, tblPurchases.Store FROM tblPurchases;
When I am in the database and access the column's pull down, I get ALL records, including duplicates (so OfficeMax is listed 3 times.) How do I get it so I only see
Staples
OfficeMax
in the pull down when in the database?
Thanks!
View 4 Replies
View Related
Nov 28, 2007
I want to insert data into a table where a symbol does not already exist for that date. I am not sure what i am doing anymore :( So please help me verify that this won't insert duplicates? Am i using the correct logic? :confused:
"INSERT INTO StocksData (Symbol, [Security Name], [Market Category], " & _
"[Reg SHO Threshold Flag], FileDate) " & _
"SELECT DISTINCT Symbol, [Security Name], [Market Category], " & _
"[Reg SHO Threshold Flag], '" & fileDate & "'" & _
"FROM " & sTableName & _
" WHERE ((Symbol Not In (select Symbol from StocksData)) AND (" & _
fileDate & " Not In (select FileDate from StocksData)));"
View 3 Replies
View Related
Jul 30, 2013
I would like to use an append query that appends data from a union query into a table, but doesn't add duplicates based on a certain field.
I have been trying to use this code, but it doesnt seem to work.
INSERT INTO [Cotton13/14]
SELECT DISTINCT [Contracted Farmers].*
FROM [Contracted Farmers]
WHERE NOT (SELECT * FROM [Cotton13/14] FROM [Cotton13/14] AS [Cotton13/14] WHERE [Cotton13/14].[OF Codec] = [Contracted Farmers].[OF Codec])
Cotton13/14 is the table I want to append to and Contracted Farmers is the union query. However the code is giving me an error.
View 7 Replies
View Related
Sep 11, 2013
I'm attempting to create an append query that will add new records only if there isn't an equivalent record already existing. Typically I would add the existing table to the query, and only add new records if the same do not exist. In this case, the table is maintaining records over time (start date and end date).
I have 4 tables:
[t_employees]
employee_ID
employee_name
[t_cities]
city_ID
citiy_name
[t_city_assignment]
city_assignment_ID
start_date
end_date
employee_ID
city_ID
[t_temp_employees]
effective_date
employee_ID
city_ID
I'm checking if [t_temp_employees].[effective_date] <> [t_city_assignment].[start_date]. However, if the employee has historical entries it will still add a record (in fact, it'll add multiple records).
How can I append a new record only if one for the same time period does not exist?
View 1 Replies
View Related
Mar 12, 2015
I have two tables, tblCandidate and tblNewHire. I am trying to transfer candidates to tblNewHire based on the date they are hired. However, I would like the database to skip any records that are already in tblNewHire, just in case someone inadvertently puts in the wrong date when running the query.
I created an append query (SQL below) but this enters the data regardless of duplication. I need to be able to check both SSN and LastName against the new table and can't set either one to be unique values as it's possible there could be two candidates with the same last name.
Any way to do this by creating a recordset and looping through to check for dupes.
INSERT INTO tblNewHire ( SSN, FirstName, MiddleName, LastName, Phone, Email, EOD, HiringMechanism )
SELECT tblCandidate.SSN, tblCandidate.FirstName, tblCandidate.MiddleName, tblCandidate.LastName, tblCandidate.Phone, tblCandidate.Email, tblCandidateTracking.ActionDate, tblCandidateTracking.HireMechanism
FROM tblCandidate INNER JOIN tblCandidateTracking ON tblCandidate.SSN = tblCandidateTracking.SSN
WHERE (((tblCandidateTracking.ActionDate)=[forms]![frmNewHireMain]![txtEODDate]) AND ((tblCandidateTracking.LastAction)="EOD"));
View 2 Replies
View Related
Feb 18, 2007
hi Guys,
I have been looking at different post and checking Microsoft help files as well, but still can't seem to fix this problem.
I am having 2 tables. The first table is connected to a form for viewing and entering data, and in the second table i am just copying 3-4 fields from the first table.
I am trying to use the insert statement to insert records in the second table, and everytime i click on the "Add" button to add the records i get the following error "MS access can't append all the records in the append query ... blah blah blah"
However if i close the form and reopen it, and goto the record (as it is saved in the first database) and now click on the add button to add the fields to the second table/database, it works.
What am i doing wrong???
Any inputs will be greatly appreciated.
View 3 Replies
View Related
Feb 12, 2008
Hi this is my first post... so hi all :)
ok what i have is a table with contact details 900k plus
there are about 90k of which are duplicates.
this is the basic feilds that are important in this case.
Id, data_source, data_recived, data_code,
what i want is to have a table with unique records (no dups in data_code)
this table will look like this...
Id, data_code, Num_dups, dup1_source, dup1_date, daysbtw_Dup1_dup2, dup2_source, dup2_date, daysbtw_Dup2_dup3 ,dup3_source, dup3_date, daysbtw_Dup3_dup4 ,dup4_source, dup4_date,
I know there is no more than 4 dups of each record.
what i want from this is a table that will give me a record of how many dups for each record then all the dates that they were added and the date between each record entry.
if anyone can help it would be great .
thanks in advance.
View 6 Replies
View Related
Dec 8, 2005
Hey, all! Thanks for helping, here is my situation.
I have a table with about 70,000 records that have duplicate Address field values. The rest of the field values for those records are different. When I do a find duplicate querry I get the result that 17,000 records have the same address. However, when I do the append qurrey as instructed here: http://support.microsoft.com/?kbid=209183 I get a total of only 600 records in the new table. I have tried deleting all of the indexes for both the new and old table, with no luck.
I'm using Access 2000 on XP Pro.
If anyone could help with this I would greatly appreciate it!
Thanks
Will
View 14 Replies
View Related
Aug 23, 2005
I have a table in a healthcare patient database that stores Admitting Number, Scan Number, Last Name, and some other fields detailing the scan. Each patient can have multiple scans and I'm trying to design a query that lists how many scans each patient has had by finding all the duplicate admitting numbers. I'm using this SQL statement:
SELECT MultScans.Admitting_Number, Count(MultScans.Admitting_Number) AS Num_Of_Scans
FROM MultScans
GROUP BY MultScans.Admitting_Number
HAVING (((Count(MultScans.Admitting_Number))>1));
which works fine but I can't figure out how to also print out the last name, scan number and the other fields in this query. If I add the field to the select part it says I can't because the expression is not part of the aggregate function and if I add the expression to the 'group by' the query runs but displays all the duplicates. Thanks for any help.
View 3 Replies
View Related
Apr 4, 2006
Please help. I am having difficulty understanding why a subform is showing duplicates despite using SELECT DISTINCT for its query. I have looked all over the forum but am still quite confused.
I think my database is normalised but this may be the problem and can attach it if necessary.
My query is as follows
SELECT DISTINCT StudentAndCourse.ClassID, StudentAndCourse.LevelID, StudentAndCourse.StudentID
FROM [Level] INNER JOIN (Class INNER JOIN StudentAndCourse ON Class.ClassID=StudentAndCourse.ClassID) ON Level.LevelID=StudentAndCourse.LevelID;
Any help would be most appreciated as I cannot understand what is going wrong.
View 1 Replies
View Related
May 1, 2007
Hello,
I am just wondering whether there is any way I could run a simple query that would pull all the data I need and inform me of the duplicates if there is any.
Thanks!
View 2 Replies
View Related
Mar 25, 2008
Hi everyone.
I have a query linking 2 tables. The idea of the query was to show our longest serving customers. The one table contains CustNo, Address details, etc and the second table contains AccNo, CurrBal, AccType, CustNo, etc etc. (note the bold fields are the primary keys). However this is bringing back results on account level rather than customer level, i.e CustNo 3 might Have AccNo xxxxxx, AccNo xxxxx1, AccNo xxxxxx2. How do I get it to show the 'oldest' account for each customer. So it will only show each customer once and that customers oldest account. Heres the SQL for the query. Hope someone can help. Thanks
SELECT DBSINV97.DateOpen, DBSINV97.AccNo, DBSINV97.CustNo, DBSINV97.PostalName, DBSINV97.CurBal, DBSINV97.AccType, DBSINV97.DateClose, DBSCUS01A.Title, DBSCUS01A.Initial, DBSCUS01A.Surname, DBSCUS01A.Street, DBSCUS01A.District, DBSCUS01A.Town, DBSCUS01A.County, DBSCUS01A.Postcode
FROM DBSINV97 INNER JOIN DBSCUS01A ON DBSINV97.CustNo = DBSCUS01A.CustNo
WHERE (((DBSINV97.DateOpen)<"2002-01-01") AND ((DBSINV97.DateClose)="1800-01-01"));
View 1 Replies
View Related
Mar 26, 2008
I've been researching and reading about how to eliminate duplicates in my Query, but all the suggestions don't seem to work. Here is my problem:
I want to create a Query with information from 2 Tables. Ultimately, I want my Query to be a malining list that I will be sending requests to. But, I want only the names, addesses, etc. of the people who fit certain criteria (info. stored in several different fields of the two tables). So, if a person matches two of my specified criteria, they appear twice in my query. Or if they fit all the criteria, they might appear 5 or 6 times. I want each name and address to show up once, even though the person may fit into several criteria. Does this makes sense?
I've tried typing "DISTINCT" after "SELECT" in SQL, but that didn't do anything. I've also tried changing the "Unique Values" to YES, but that didn't work either.
Sorry if it's unclear, but I am very new to Access! :(
View 7 Replies
View Related
Nov 24, 2004
Hello
I've created a query that finds duplicate records in a table. I've also made a form based on that query that shows some fields of the duplicate recoeds found. In that form there's also a textbox that counts the records found (using the count([field]) function). Everything works perfectly when there are duplicate records. However, when there are no duplicates , I'd like the textbox value to be 0 (it shows nothing now obviously because the query returns no records), as long as some other actions to be performed. How can I check (in the vb code or somehow else) if the query returns no records as a result ? Thanks in advance
View 3 Replies
View Related
Jan 9, 2006
Friends,
I have a table with 3 fields:
NAME
AMOUNT1
AMOUNT2
Field AMOUNT1 and AMOUNT 2 can have the same data and I need to run a query which will return records with similar data in both fields. Both fields are text (5 characters) and the match has to be done on the first four characters.
Please note that I have tried with a Find Duplicates query but does not seem to return all the records with showing the same data probably to the fact the the last character is different.
Any help? Thank you.
View 3 Replies
View Related
Aug 14, 2006
I am running a query to return records from a table. I want to eliminate records from the query if the values contained in one field are duplicated. I have tried using the DISTINCT keyword but it only works if the entire record is unique or if I was retieving just one field
Any suggestions appreciated
View 1 Replies
View Related
Aug 1, 2007
I am using a combo box to assign gun numbers on an employee form (frmemployees). I also have a query listing only the gun numbers that have been assigned. When I select a gun from my combo box, I what to evaluate if it is already on the gun assignment query. That way I cannot assign the same gun to two different people. I am using the before_update event to do this. The code that I am using is as follows:
Private Sub intgunNumber_BeforeUpdate(Cancel As Integer)
If DLookup([intgunNumber], "qrygunassignmentcurrent", Me.intgunNumber) = Me.intgunNumber Then
MsgBox "Item # is already listed.", vbOK, "DUPLICATE FOUND"
Cancel = True
End If
"me" represents my frmemployees form. The problem is that it's causing an event even for the numbers that aren't listed on the query. I am trying to get the evaluation correct but am having difficulties. All the fields are numeric fields. :( :mad:
View 6 Replies
View Related
May 13, 2005
I have a Duplicates Query that extract the following information from my Table
Name Surname DOB Joined
The query then extracts info such as...
Bill Smith 25:12:70 1999
Bill Smith 25:12:70 2005
Most of the time the 'Joined' field has the same year. But I need to find the ones where the year differs but the rest of the information is exactly the same. Because there is 15000 odd records to check, I thought that there would be a quicker way to check.
Could someone please assist me with this query if it is possible?
Thank you in advance.
View 1 Replies
View Related
Nov 25, 2005
I have the following two querys which are supposed to return only the latest Note for a Prospect.
QRYNotes
SELECT TBLNotes.ProspectID AS Expr1, Max(TBLNotes.NoteDate) AS MaxOfNoteDate
FROM TBLNotes
GROUP BY TBLNotes.ProspectID;
QRYNotes2
SELECT DISTINCT TBLProspects.CompanyName, TBLNotes.NoteID, TBLNotes.Note, TBLNotes.NoteDate
FROM (TBLProspects INNER JOIN TBLNotes ON TBLProspects.ProspectID=TBLNotes.ProspectID) INNER JOIN QRYNotes ON TBLNotes.NoteDate=QRYNotes.MaxOfNoteDate;
When I run the QRYNotes2, I get more than one record per Prospect instead of just the newest NoteDate.
What is wrong?
View 3 Replies
View Related
Jul 31, 2006
Hi All.
I have a db, with, amongst others, one form that I enter job details, and another form that I enter the materials for the job. These forms are linked by the ID_Number. This all works fine
I have a query that links both these forms together, so when the query is run, it shows the ID_Number of all jobs that have been done completed between dates, whether they have materials assigned to them or not.
This all works fine, but if for example, there are 10 jobs in one month and one of those jobs have more than one material booked against them, then that job number will show twice.
What I would like to do is "Hide Duplicates" on the query.
Can someone help?
Many thanks.
Frank.
View 1 Replies
View Related
Apr 4, 2007
I have a query that includes the following fields
Year
EventNumber
CorrectiveActionNumber
ResponsibleGroup
Committment
Each event will have multiple corrective actions. For each corrective action assigned to a group, the "committment" is also assigned to them, but I also have to assigned a committment to our group (SRG). So this makes the query results show two records for each corrective action, one with the group assigned committment and one for my groups committment. I need a query that will show corrective actions that have the group committment assigned but not a corresponding SRG committment assigned. However since my query results in two separate records, I am unsure how to do this.
Any suggestions?
Thanks,
Jim
View 4 Replies
View Related
Jun 6, 2007
hi all, im trying to make a query so that when someone updates a field in a form it searches a table (Companytable) which is a list of company names. If it exists i want it to then display a msgbox " already exists" sort of thing! trying to do this in the criteria field on the query. anyone have any ideas or useful resources, ive not done this for a while and cant remember much of IF THEN sort of stuff. mainly not sure if im barking up the right tree, i can search dependent on a set value but not sure how to do it dependant on whats been typed into a form..any pointers would be appreciated! thanks! James
View 2 Replies
View Related
Jun 15, 2007
Hi,
Our Contacts database has around 4000 individual contacts (and growing), which have been pulled together from four or five seperately maintained databases. As such there are bound to be duplicate records.
What would be a good way of querying the database to find duplicate entries (i.e. entries where the first name and surname are the same)? Short of putting everything in alphabetical order and manually scanning them to see if there are two names the same next to each other I don't know of a way to do it. Also, the manually-scanning method won't work if the names are spelled a little differently (Davies and Davis).
Any ideas?
View 1 Replies
View Related
Nov 4, 2007
Hey All
I have 2 tables - A and B
I am assigning trade ID from A to B, where they have several common fields.
Two conditions are needed.
a) Only update records where B doesn't have trade ID yet. (done)
b) Do not update records with a Trade ID , if such id is in a a Table B.
not sure how to do the second one; would making Trade ID - primary key help ?
here is the text --
UPDATE tbl_eblotter_feed INNER JOIN tbl_broker_1 ON (tbl_eblotter_feed.nm_brokers = tbl_broker_1.Broker_ID) AND (tbl_eblotter_feed.CUSIP = tbl_broker_1.CUSIP) AND (tbl_eblotter_feed.SPN = tbl_broker_1.spn_cparty) AND (tbl_eblotter_feed.dt_mat = tbl_broker_1.dt_mat) AND (tbl_eblotter_feed.amt_notional = tbl_broker_1.amt_notional) SET tbl_broker_1.M3_ID = [tbl_eblotter_Feed].[M3_Id], tbl_broker_1.Desk = [tbl_eblotter_Feed].[Desk]
WHERE (((tbl_broker_1.M3_ID) Is Null));
View 2 Replies
View Related
Jan 4, 2008
I know I have duplicate records in a table and therefore I used the "Find duplicates Query Wizard" to identify the duplicates.
I am positive - there are duplicates and the query does not perform the way it should be.
Any suggestion will be appreciated.
TKS
JLA
View 9 Replies
View Related