Monday, March 12, 2012

Referencing a field in another table as part of a formula in a computed column

Hi guys, I am new to all of this stuff so please bare with me. I will try to explain this as simply as I can. I have 2 tables.. Table1 and Table2 they are linked using both the STOCKCODE and SUPPLIER fields. In Table 1 is the STOCKCODE, LENGTH AND SUPPLIER fields (there are others but these are the 3 that I need to use) In Table2 is STOCKCODE, SUPPLIER and SUPPLER_MASS. What I want to do is put a calculated column into Table2. The formula I need is fairly simple it is: 1/(LENGTH*SUPPLIER_MASS)

Ok so here is what I would like:

1/(SUPPLIER_MASS*(SELECT Table1.LENGTH FROM Table1 WHERE Table1.STOCKCODE=Table2.STOCKCODE AND Table1.SUPPLIER=Table2.SUPPLIER)

From what I understand I can't have a query in a calculated column's "formula" field?

So how would I do this? I don't want to run a query because LENGTH or SUPPLIER_MASS could change on a day to day basis meaning I will have to run the query everything one of these changes. The benefit of having the calculated column is that it will update as soon as LENGTH or SUPPLIER_MASS changes.

Is there any way I can do this?

Thanks guys (and girls)You can have insert, update trigger which will update calculated column every time you update a record or insert a new one.

Thank you.

No comments:

Post a Comment