简体   繁体   中英

Access table field calculated with query

Is it possible to set a field of a table to take a value dynamically from a query?

For example, I have this table ITEM(ID).

I insert a new record in ITEM_STORE (ITEM_NAME,COLOR,PRICE) and set the field PRICE.

For example, to take value from -

 (SELECT DISTINCT PRICE FROM ITEM WHERE ITEM_STORE.ITEM_NAME = ITEM.ID)

You can do that but you have to make sure that the subquery returns only one value (in case there is more than one possible price in the items table) so instead of using

(SELECT DISTINCT PRICE FROM ITEM WHERE ITEM_STORE.ITEM_NAME = ITEM.ID)

You should use

(SELECT Top 1 PRICE FROM ITEM WHERE ITEM_STORE.ITEM_NAME = ITEM.ID)

Good luck!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM