Jump to content
Claris Engage 2025 - March 25-26 Austin Texas ×

How do I set an id field based on result of other field matching


This topic is 6980 days old. Please don't post here. Open a new topic instead.

Recommended Posts

  • Newbies
Posted (edited)

I'm new to FM so correct me if I am wrong with any statements or assumptions:

I have 2 tables.

product

id

cat_id

tmpCat

Categories

id

Category

Categories has unqiue values in 'Category' cloumn.

Products has multiple rows with the same value for 'tmpCat'.

I am trying to set for each row:

'Products::cat_id' = 'Categories::id' where Products::tmpCat = Categories::Category

I want to do this for all rows in Products.

The reason:

yes Products is not normalised as 'tmpCat' should not exist but this is due to an import from a non normalised table that combined both Products and Categories (and others tables not mentioned) together.

I could only import to one table at a time so I imported from the existing table twice ( once for Products and again for Categories ).

I then removed all duplicates from Categories.

I have created a realtionship between Products::cat_id and Categories::id.

In SQL it would be simply a matter of :

UPDATE Products p SET p.cat_id = (SELECT c.id FROM categories c WHERE c.category = p.tmpCat )

thank you in advance for your help.

Edited by Guest
Posted

You just need to do a "switcheroo." This is pretty common when you are building from flat-file data. Just as you have a tmpCat field, with the full Category name, you need a temporary relationship, from tmpCat to the Category name in Categories. Assuming that spelling is consistent you should be able to do a Replace (on all Product records), with Calculation, using that temporary relationship, putting the id field from Categories into the Products cat_id field. Then you can delete the temporary field and relationship.

(P.S. In case you don't know, to do a Replace put your cursor in the cat_id field in Products. Be sure to backup first, as Replace cannot be "undone," and it's possible to mess up the field in the entire table.)

  • Newbies
Posted

THANKS!!

got the same answer from Nelluk ( #filemaker irc on efnet ).

Funny thing he tried to explain this yesterday to me but didn't use the important term 'switcheroo' which explains the action quite well (seriously).

I kept forming a duel relationship (id + category) which obviously failed.

This topic is 6980 days old. Please don't post here. Open a new topic instead.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.