473,414 Members | 1,567 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,414 software developers and data experts.

Append query without duplicate rows; restrict in query

I was able to create a multiple field unique index for the EI&Fees table, restricting to unique values for FacilityId, EmissionInvYear, and FeeYear; however, can you show me how to apply the same restriction in the query? Here is the SQL for the query:

Expand|Select|Wrap|Line Numbers
  1. INSERT INTO [EI&Fees] ( FacilityID, [Permit#], EmissionInvYear, FeeYear )
  2. SELECT [Records to Append to EI&Fees, Active-Pending Query].FacilityID, [Records to Append to EI&Fees, Active-Pending Query].[Permit #], [Records to Append to EI&Fees, Active-Pending Query].EmissionInvYear, [Records to Append to EI&Fees, Active-Pending Query].FeeYear
  3. FROM [Records to Append to EI&Fees, Active-Pending Query];
Jun 15 '15 #1
8 2170
Rabbit
12,516 Expert Mod 8TB
Please use code tags when posting code or formatted data.

Put DISTINCT after the select.
Jun 15 '15 #2
This works; but I need to receive data for all fields in records added. If only one of the above four fields has unique data (compared to records already in the table being appended) then the record is appended, but the other three fields have blank values for the record(s) appended--I need to append the values for all four fields. Can you understand what I'm asking, and perhaps help? Thanks!
Jun 18 '15 #3
Rabbit
12,516 Expert Mod 8TB
Use the WHERE clause to filter out the blanks.
Jun 18 '15 #4
Thanks for your QUICK response. I don't know how to create the WHERE clause. When I'm in design view and open the datasheet view of the SELECT DISTINCT query, I get 56 records having four columns none of which have blank data. But when I RUN this query it allows only one record to be appended (as appropriate)--that record has different data in the Permit# field but same data in FacilityID, EmissInvYear, and FeeYear fields compared with existing records in the table they were appended to. How can I get this query to show the values (not blanks) in the table they are appended to? Will a WHERE clause work? Can you give me an example? Sorry if I'm not clear here--and thanks for any help you can give!
Jun 18 '15 #5
Rabbit
12,516 Expert Mod 8TB
I'm sorry. Can you try explaining again with sample data? I'm completely confused by your explanations.

You said there was blank data and you wanted to exclude them. But now you're saying there is no blank data. Also, you said there are 56 unique records, but only 1 gets appended. Which doesn't make sense, because if they're unique, that means they don't violate the index, and all of them should be appended.
Jun 19 '15 #6
Please see attached pdf file.

Thanks for trying to help, and sorry for confusion.
If can't get SQL select DISTINCT query to work, will add index to the table to which records will be appended (unless you have another suggestion).

Maybe I should try bracketing all four fields--not only Field2--in the first line of the query?
Attached Files
File Type: pdf EI&Fees.pdf (108.0 KB, 191 views)
Jun 19 '15 #7
Rabbit
12,516 Expert Mod 8TB
The values should be there assuming everything is spelled correctly and is syntactically correct. the DISTINCT clause doesn't blank out values. This is the first thing you should check and fix.

The second thing is that it seems like you're not (only) looking for uniqueness in the record set that you're going to insert. But also looking for uniqueness in the table you are inserting into. To accomplish that, you will need to outer join the query to the main table on the key fields and only return the ones where the key fields in the main table are null, i.e. that they don't exist in the main table.
Jun 19 '15 #8
I'll check all this on Monday--thanks!
Jun 19 '15 #9

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

Similar topics

2
by: anita | last post by:
I am sorry if this sounds as a silly problem. I have table 1 with 10 records and table 2 with 20 records. I want to append 20 records from Table 2 to table 1. But when I run the append query, the...
5
by: KayC | last post by:
Hi I use SQLServer2000 and MS Access2000 I have the below SQL query which will not work as a Access PassThrough Query, I have tried replacing the @COB with a date string but the query hangs...
1
by: HH | last post by:
To append a single record, without getting a warning if a record already exists, I found out the following syntax works fine as Query in MS Access: first create a simple 'products' table... ...
2
by: David Shears | last post by:
I am trying to use an append query to add data to another table i have. I have tableA and tableB. tableA has 1000 rows while tableB has 800 rows. i would like to add the other 200 rows in tableA to...
5
Fspinelli
by: Fspinelli | last post by:
I have an append query which takes data from a query and updates a table. However, instead of one record I get 3 or 4 of the same records dumped into the table. I might enter three records, press...
2
by: awwwebbie | last post by:
Using Access 2007, I'm trying to append records to a table using an append query. Upon completion, I get a message that "0" rows will be appended. If I change the query to a Select query, I get one...
9
by: ricardusmaximus | last post by:
Hi guys. I am using an Append Query to add records to an Archive Table in an MS Access Application. The code generates 2 records for each one identified. strSQLAppend(1) = "INSERT INTO...
4
by: confused1 | last post by:
I need to calculate which products were purchased by a specific customer in 2014, using Microsoft SQL Server Management Studio 2008. I am trying to combine data from 3 semi-related tables:...
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:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.