collected related records to populate table

  • Thread starter Thread starter MM
  • Start date Start date
M

MM

I would like to automate the append/update of a related items table
[tblRelatedItems] for our
B2B web. I`m not sure how to collect and identify the "related" items
to append/update.

Our product is books so related items are where the author or series
is the same. The details to located related items are in our Inventory
Table [tblInventory]

Thanks in advance for any help, table details and data sample with
results are below.

[tblInventory]
ID
ProdCode
Title
Author
Series
Price
ReleaseDate
Category
SubCategory1
SubCategory2
SubCategory3
many more fields not required for this example last cost, avg cost,
last recipt, last sale etc etc etc...

[tblRelatedItems]
ID
ProdCode
RelatedItem (this is ProdCode for the realted item)
LastUpdated
LastUpdatedBy

SAMPLE DATA with Result

[tblInventory]
ProdCode Title Author
123456790 Title One Author 1
123456791 Title Two Author 1
123456792 Title Three Author 1
123456793 Title Four Author 1
123456794 Title Five Author 1
These titles would create this in related items

[tblRelatedItems]
ProdCode RelatedItem
123456790 123456791
123456790 123456792
123456790 123456793
123456790 123456794
123456791 123456791
123456791 123456792
123456791 123456793
123456791 123456794
123456792 123456793
123456792 123456794
123456792 123456790
123456792 123456791
123456793 123456794
123456793 123456790
123456793 123456791
123456793 123456792
123456794 123456793
123456794 123456790
123456794 123456791
123456794 123456792
MM
 
Hi

Use an append query like the following to add related items...

INSERT INTO tblRelatedItems ( ProdCode, RelatedItem, LastUpdated,
LastUpdatedBy )
SELECT tblInventory.ProdCode, tblInventoryRelated.ProdCode, Now(), currentuser
FROM tblInventory, tblInventory AS tblInventoryRelated
WHERE ((tblInventory.ProdCode <> [tblInventoryRelated].[ProdCode]) AND
(tblInventory.Author=[tblInventoryRelated].[author])) OR
((tblInventory.ProdCode <> [tblInventoryRelated].[ProdCode]) AND
(tblInventory.Series=[tblInventoryRelated].[series]))

There are 2 approaches...

1) Delete * from tblRelatedItems then run the above

or 2) step 1: expand the above to delete from tblRelatedItems any records
that are no longer related then
step 2: expand the above to insert any records that aren't already in
tblRelatedItems

I prefer the simpler first approach but you may have reasons to use the second

hth

Andy Hull
 
Hi

Use an append query like the following to add related items...

INSERT INTO tblRelatedItems ( ProdCode, RelatedItem, LastUpdated,
LastUpdatedBy )
SELECT tblInventory.ProdCode, tblInventoryRelated.ProdCode, Now(), currentuser
FROM tblInventory, tblInventory AS tblInventoryRelated
WHERE ((tblInventory.ProdCode <> [tblInventoryRelated].[ProdCode]) AND
(tblInventory.Author=[tblInventoryRelated].[author])) OR
((tblInventory.ProdCode <> [tblInventoryRelated].[ProdCode]) AND
(tblInventory.Series=[tblInventoryRelated].[series]))

There are 2 approaches...

1) Delete * from tblRelatedItems then run the above

or 2) step 1: expand the above to delete from tblRelatedItems any records
that are no longer related then
step 2: expand the above to insert any records that aren't already in
tblRelatedItems

I prefer the simpler first approach but you may have reasons to use the second

hth

Andy Hull



MM said:
I would like to automate the append/update of a related items table
[tblRelatedItems] for our
B2B web. I`m not sure how to collect and identify the "related" items
to append/update.
Our product is books so related items are where the author or series
is the same. The details to located related items are in our Inventory
Table [tblInventory]
Thanks in advance for any help, table details and data sample with
results are below.
[tblInventory]
ID
ProdCode
Title
Author
Series
Price
ReleaseDate
Category
SubCategory1
SubCategory2
SubCategory3
many more fields not required for this example last cost, avg cost,
last recipt, last sale etc etc etc...
[tblRelatedItems]
ID
ProdCode
RelatedItem (this is ProdCode for the realted item)
LastUpdated
LastUpdatedBy
SAMPLE DATA with Result
[tblInventory]
ProdCode Title Author
123456790 Title One Author 1
123456791 Title Two Author 1
123456792 Title Three Author 1
123456793 Title Four Author 1
123456794 Title Five Author 1
These titles would create this in related items
[tblRelatedItems]
ProdCode RelatedItem
123456790 123456791
123456790 123456792
123456790 123456793
123456790 123456794
123456791 123456791
123456791 123456792
123456791 123456793
123456791 123456794
123456792 123456793
123456792 123456794
123456792 123456790
123456792 123456791
123456793 123456794
123456793 123456790
123456793 123456791
123456793 123456792
123456794 123456793
123456794 123456790
123456794 123456791
123456794 123456792
MM- Hide quoted text -

- Show quoted text -

Thanks for your post! I'll give it a go and see what happens.

Pat
 
Use an append query like the following to add related items...
INSERT INTO tblRelatedItems ( ProdCode, RelatedItem, LastUpdated,
LastUpdatedBy )
SELECT tblInventory.ProdCode, tblInventoryRelated.ProdCode, Now(), currentuser
FROM tblInventory, tblInventory AS tblInventoryRelated
WHERE ((tblInventory.ProdCode <> [tblInventoryRelated].[ProdCode]) AND
(tblInventory.Author=[tblInventoryRelated].[author])) OR
((tblInventory.ProdCode <> [tblInventoryRelated].[ProdCode]) AND
(tblInventory.Series=[tblInventoryRelated].[series]))
There are 2 approaches...
1) Delete * from tblRelatedItems then run the above
or 2) step 1: expand the above to delete from tblRelatedItems any records
that are no longer related then
step 2: expand the above to insert any records that aren't already in
tblRelatedItems
I prefer the simpler first approach but you may have reasons to use the second

Andy Hull
MM said:
I would like to automate the append/update of a related items table
[tblRelatedItems] for our
B2B web. I`m not sure how to collect and identify the "related" items
to append/update.
Our product is books so related items are where the author or series
is the same. The details to located related items are in our Inventory
Table [tblInventory]
Thanks in advance for any help, table details and data sample with
results are below.
[tblInventory]
ID
ProdCode
Title
Author
Series
Price
ReleaseDate
Category
SubCategory1
SubCategory2
SubCategory3
many more fields not required for this example last cost, avg cost,
last recipt, last sale etc etc etc...
[tblRelatedItems]
ID
ProdCode
RelatedItem (this is ProdCode for the realted item)
LastUpdated
LastUpdatedBy
SAMPLE DATA with Result
[tblInventory]
ProdCode Title Author
123456790 Title One Author 1
123456791 Title Two Author 1
123456792 Title Three Author 1
123456793 Title Four Author 1
123456794 Title Five Author 1
These titles would create this in related items
[tblRelatedItems]
ProdCode RelatedItem
123456790 123456791
123456790 123456792
123456790 123456793
123456790 123456794
123456791 123456791
123456791 123456792
123456791 123456793
123456791 123456794
123456792 123456793
123456792 123456794
123456792 123456790
123456792 123456791
123456793 123456794
123456793 123456790
123456793 123456791
123456793 123456792
123456794 123456793
123456794 123456790
123456794 123456791
123456794 123456792
MM- Hide quoted text -
- Show quoted text -

Thanks for your post! I'll give it a go and see what happens.

Pat- Hide quoted text -

- Show quoted text -

perfect!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top