Smart questions
Smart answers
Smart people
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Member Login

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips now!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

Join Tek-Tips
*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

LINK TO THIS FORUM!

Add Stickiness To Your Site By Linking To This Professionally Managed Technical Forum.
Just copy and paste the
code below into your site.

Partner With Us!

"Best Of Breed" Forums Add Stickiness To Your Site
Partner Button
(Download This Button Today!)

Feedback

"...Within the first afternoon I found 2 of the 3 needed solutions, and the 3rd came to me over the weekend!..."

Geography

Where in the world do Tek-Tips members come from?
kjschmitz (TechnicalUser)
20 Apr 12 13:27
Basically I am trying to combine certain fields from two tables into one using an append query.  The trick comes in that I want to only include records that have changed since the query was last run.  When I first run my query, I get the results expected to populate the desired table (Unit_Bid_test).

I must not be nesting my WHERE Clause correctly, because I can pass updates from my Unit_Pricing table just fine, but updates made to my Eligible_Bidders table are unseccessful.  Here is the base query:

CODE

INSERT INTO Unit_Bid_test ( Bid_Tab_ID, Unit_Price_ID )
SELECT Eligible_Bidders.Bid_Tab_ID, Unit_Pricing.Unit_Price_ID
FROM Eligible_Bidders, Unit_Pricing

WHERE (((Unit_Pricing.Project_ID)=[Eligible_Bidders].[Project_ID])) OR (((Eligible_Bidders.Project_ID)=[Unit_Pricing].[Project_ID]));

I have added criteria to the WHERE clause in an attempt to limit the appending of the table to new records:

CODE

INSERT INTO Unit_Bid_test ( Bid_Tab_ID, Unit_Price_ID )
SELECT Eligible_Bidders.Bid_Tab_ID, Unit_Pricing.Unit_Price_ID
FROM Eligible_Bidders, Unit_Pricing

WHERE (((Eligible_Bidders.Bid_Tab_ID) Not In (select Bid_Tab_ID from Eligible_Bidders)) AND ((Unit_Pricing.Project_ID)=[Eligible_Bidders].[Project_ID])) OR (((Unit_Pricing.Unit_Price_ID) Not In (select Unit_Price_ID from Unit_Bid_test)) AND ((Eligible_Bidders.Project_ID)=[Unit_Pricing].[Project_ID]));

This seems to work for updates made to the Unit_Pricing table, but not updates made to the Eligible_Bidders table.

Any idea how to nest the WHERE statement to correct this issue?
kjschmitz (TechnicalUser)
21 Apr 12 10:51
Lack access to the DB right now, but I think my issue was using:

CODE

((Eligible_Bidders.Bid_Tab_ID) Not In (select Bid_Tab_ID from Eligible_Bidders))

and not

CODE

((Eligible_Bidders.Bid_Tab_ID) Not In (select Bid_Tab_ID from Unit_Bid_test))




 
JonFer (Programmer)
21 Apr 12 19:52
What are the primary keys for each table?
kjschmitz (TechnicalUser)
23 Apr 12 8:43
My table structure is as follows:

CODE

Eligible_Bidders
   Bid_Tab_ID   dbLong  PrimaryKey  Indexed
   Project_ID   dbLong  ForiegnKey  Indexed
   Contractor_ID   dbLong  ForiegnKey  Indexed
   Bid_Amount   dbCurrency

Unit_Bid_test
   Unit_Tab_ID   dbLong  PrimaryKey  Indexed
   Bid_Tab_ID   dbLong  ForiegnKey  Indexed
   Unit_Price_ID   dbLong  ForiegnKey  Indexed
   Unit_Amount   dbCurrency

Unit_Pricing
   Unit_Price_ID   dbLong  PrimaryKey  Indexed
   Project_ID   dbLong
   Unit_Price_Number   dbLong
   Unit_Price_Desc   dbText

The Eligible_Bidders table is created using a many to many relationship between a Projects table and a Contractors table.  The Projects_ID field is also found in the Unit_Pricing table to that Project Managers can add a unit cost to a given project.  

And I have confirmed that the changes work:

CODE


INSERT INTO Unit_Bid_test ( Bid_Tab_ID, Unit_Price_ID )
SELECT Eligible_Bidders.Bid_Tab_ID, Unit_Pricing.Unit_Price_ID
FROM Eligible_Bidders, Unit_Pricing
WHERE (((Eligible_Bidders.Bid_Tab_ID) Not In (select Bid_Tab_ID from Unit_Bid_test)) AND ((Unit_Pricing.Project_ID)=[Eligible_Bidders].[Project_ID])) OR (((Unit_Pricing.Unit_Price_ID) Not In (select Unit_Price_ID from Unit_Bid_test)) AND ((Eligible_Bidders.Project_ID)=[Unit_Pricing].[Project_ID]));

I am now working to incorporate a delete query which will check for Unit Prices and Contractors that have been removed from the Unit_Pricing and Eligible_Bidders tables as well:

CODE


DELETE Unit_Bid_test.Bid_Tab_ID, Unit_Bid_test.Unit_Price_ID, Unit_Bid_test.Unit_Amount
FROM Unit_Bid_test
WHERE (((Unit_Bid_test.Bid_Tab_ID) Not In (select Bid_Tab_ID from Eligible_Bidders))) OR (((Unit_Bid_test.Unit_Price_ID) Not In (select Unit_Price_ID from Unit_Pricing)));

My question now is what best practice should I be using to execute these queries in succession?  Can I combine them into a single query?  Should I run them via VBA to ensure that the delete is done prior to the append?

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close