Re: Adding missing records to a table



Petterq,

You can just run an Append Query to complete the missing items. The SQL of this query will look something like this...
INSERT INTO Prices ( CompanyID, ItemID )
SELECT CompanyID, ItemID
FROM Companies, BasicItems
If you have a Unique Index set in the Prices table for the composite of CompanyID and ItemID, existing records will not be duplicated. Having said that, test on a backup copy first :-)


--
Steve Schapel, Microsoft Access MVP

Petterq wrote:
I have a table containing prices for items, linked to a customer database. One key is CompanyID, indicating what company the spesific price is valid for.

There is a certain basic amount of items that should be valid for all companies. Theese items is linked to a test customerID.

I would like to make a query that adds any records missing from the basic amount of items to the companies missing them.

I.e. if one itemID is 30, and should be valid for all companies. This item might be missing for a certain percentage of the customers in the database. The query should add a record with itemID 30 and the customerID for each customer that misses the record, ignoring those who already have it.

Any hints?
.



Relevant Pages

  • Re: tempdb grows to 8G suddenly
    ... that a join predicate is missing. ... >> to someone running a query which has a join that has not been qualified ... a huge result set gets built up (in tempdb ...
    (microsoft.public.sqlserver.server)
  • RE: Linking Combo Boxes on a Form
    ... SELECT CategoryID, Category FROM ProposalCategories; ... The gist of my database is to create a order form where the prices of the ... The list of products is extremely long and I wanted to filter ... This subform is based on a query that calculates the product price based on ...
    (microsoft.public.access.forms)
  • Re: listing records with only the newest date show.
    ... There is rarely a good use of "LAST" in a query. ... > as the prices are diferent they are not actually duplicate records. ... >> Duane Hookom ...
    (microsoft.public.access.reports)
  • Re: Need help with following SQL... anyone?
    ... Query 2: Use base table linked to query 1 and perform the Group By ... DepartFrom ... offers prices ... FROM locations INNER JOIN ((offers INNER JOIN (hotels INNER JOIN ...
    (microsoft.public.access.queries)
  • Re: RM formalism supporting partial information
    ... omniscient database. ... If the user formulates a query then this will now ... If the age or occupation is missing we could ... the value-does-not-apply interpretation can always also be ...
    (comp.databases.theory)