MS Access 公式根据 "between" 两个其他字段的数量更新 table 中的一个字段

MS Access Formula to Update one field in a table based on the amount "between" two other fields

我希望有人能帮助我。我希望我可以在 MS Access 中执行更新查询,该查询将根据另一个字段 "Brand Savings" 是否等于或介于我拥有的一组美元范围之间来更新我称为 "Materiality by Fiscal Year" 的字段在另一个 table 中。第一个table如下,是初级table:

+----------+------------+---------------+----------------------------+
|  Brand   | Project ID | Brand Savings | Materiality by Fiscal Year |
+----------+------------+---------------+----------------------------+
| aBS Corp |        121 | 0,000.00   |                            |
| aBS Corp |        151 | ,640.67    |                            |
| aBS Corp |        152 | ,682.37     |                            |
| aBS Corp |        154 | 4,669.58   |                            |
| aBS Corp |        157 | ,097.00     |                            |
| aBS Corp |        159 | ,798.00    |                            |
| aBS Corp |        190 | 0,000.00   |                            |
| aBS Corp |        193 | 0,000.00   |                            |
| aBS Corp |        194 | 6,666.67   |                            |
| aBS Corp |        197 | ,799.00    |                            |
| aBS Corp |         20 | ,000.00    |                            |
| aBS Corp |        219 | ,800.00     |                            |
| aBS Corp |        222 | 2.58       |                            |
| aBS Corp |         23 | ,068.30     |                            |
| aBS Corp |        233 | ,908.60    |                            |
| aBS Corp |         25 | ,143.18     |                            |
| aBS Corp |         34 | ,674.85    |                            |
| aBS Corp |         35 | ,615.60    |                            |
| aBS Corp |         36 | ,959.28    |                            |
| aBS Corp |         39 | ,000.00    |                            |
| aBS Corp |         40 | 0,000.00   |                            |
| aBS Corp |         60 | ,000.00    |                            |
| aBS Corp |         61 | 0,094.72   |                            |
| aBS Corp |         64 | 5,000.00   |                            |
| aBS Corp |         69 | 0,000.00   |                            |
| aBS Corp |         75 | ,625.00    |                            |
+----------+------------+---------------+----------------------------+

第二个table是参考table:

+------------+-------------------+--------------------+----------------+
| FiscalYear |     Low Range     |     High Range     |     Result     |
+------------+-------------------+--------------------+----------------+
|       2016 |  (100,000,000.00) |         24,999.00  | 0-24.9K        |
|       2016 |  25,000.00        |         49,999.00  | 25-49.9K       |
|       2016 |  50,000.00        |         99,999.00  | 50-99.9K       |
|       2016 |  100,000.00       |  1,000,000,000.00  | 100K or Higher |
+------------+-------------------+--------------------+----------------+

我希望能够引用第二个 table 以便根据 "Brand Savings" 中的值是否介于 [=34] 来更新 "Materiality by fiscal Year" 字段=] 和 "High Range" 字段。但是我无法弄清楚,这让我发疯。相反,我有 4 个不同的查询将更新 "Materiality by Fiscal Year" 字段(查询中使用的公式示例如下:)

IIf(([Brand Savings]>=0) And ([Brand Savings]<=24999),"$0-24.9K")

基本上我要问的是是否有一个公式可以用来引用参考 table 中的 "Low range" 和 "High range" 字段来确定 [=主要 table 中的 31=] 值介于这两个数额之间,如果是这样,请使用参考 table?[=14 中的 "Result" 字段填充 "Materiality by Fiscal Year" 字段=]

抱歉,有点像 "wordy",只是不知道怎么解释。

谢谢大家!

您可以在更新查询中使用 DLookUp 来查找合适的值:

DLookUp("Result", "SecondTable", CDbl([Brand Savings]) & " Between [Low Range] And [High Range]")

对于 SELECT 查询,您也可以使用联接,但我怀疑这是否适用于 UPDATE 查询。

我们假设带有品牌节省的 table 称为 tblBrandSavings,带有范围的 table 称为 tblRanges。 然后你可以使用这个 UPDATE 语句:

UPDATE tblBrandSavings, tblRanges
SET [Materiality by Fiscal Year] = tblRanges.Result 
WHERE  tblBrandSavings.[Brand Savings] BETWEEN tblRanges.[Low Range] AND tblRanges.[High Range];

问题是为什么要 运行 在多个 table 中存储相同的日期。 我建议一个简单的 SELECT 语句:

SELECT tblBrandSavings.Brand, tblBrandSavings.[Project ID], tblBrandSavings.[Brand Savings], ( 
SELECT tblRanges.Result 
FROM tblRanges 
WHERE  tblBrandSavings.[Brand Savings] BETWEEN tblRanges.[Low Range] AND tblRanges.[High Range]
 ) AS [Materiality by Fiscal Year]
FROM tblBrandSavings;