The_Kurgan
Active Member
- Joined
- Jan 10, 2006
- Messages
- 270
I have two tables. The first contains customer-level data, with a Zone, # of Units, and a date. I want to match the first table to the second (represented below) and retrieve the Limit amount. Obviously, matching based on just Zone and Units is easy.
Here's the tough part: I need the query to also look at the date from the first file and match it to the Effective date in the second whereas the Table_1 date must be greater than the Table_2 date.
For example:
If a Table_1 record has a Zone of 2, Units of 3, and date of 05/15/16, the Limit to be picked should be $974,950.
If a Table_1 record has a Zone of 1, Units of 1, and date of 01/01/17, the Limit to be picked should be $431,100.
... and so on...
If I do simple left-joins on those three fields, I get a record for each of the Limits where Zone and Units match. I'm at a loss. Any thoughts would be appreciated!
Table_2
<tbody>
</tbody>
Here's the tough part: I need the query to also look at the date from the first file and match it to the Effective date in the second whereas the Table_1 date must be greater than the Table_2 date.
For example:
If a Table_1 record has a Zone of 2, Units of 3, and date of 05/15/16, the Limit to be picked should be $974,950.
If a Table_1 record has a Zone of 1, Units of 1, and date of 01/01/17, the Limit to be picked should be $431,100.
... and so on...
If I do simple left-joins on those three fields, I get a record for each of the Limits where Zone and Units match. I'm at a loss. Any thoughts would be appreciated!
Table_2
Zone | Units | Effective | Limit |
1 | 1 | 1/1/2013 | $417,000 |
1 | 2 | 1/1/2013 | $533,850 |
1 | 3 | 1/1/2013 | $645,300 |
1 | 4 | 1/1/2013 | $801,950 |
2 | 1 | 1/1/2013 | $625,500 |
2 | 2 | 1/1/2013 | $800,775 |
2 | 3 | 1/1/2013 | $967,950 |
2 | 4 | 1/1/2013 | $1,202,925 |
1 | 1 | 1/1/2016 | $424,100 |
1 | 2 | 1/1/2016 | $540,850 |
1 | 3 | 1/1/2016 | $652,300 |
1 | 4 | 1/1/2016 | $808,950 |
2 | 1 | 1/1/2016 | $632,500 |
2 | 2 | 1/1/2016 | $807,775 |
2 | 3 | 1/1/2016 | $974,950 |
2 | 4 | 1/1/2016 | $1,209,925 |
1 | 1 | 1/1/2017 | $431,100 |
1 | 2 | 1/1/2017 | $547,850 |
1 | 3 | 1/1/2017 | $659,300 |
1 | 4 | 1/1/2017 | $815,950 |
2 | 1 | 1/1/2017 | $639,500 |
2 | 2 | 1/1/2017 | $814,775 |
2 | 3 | 1/1/2017 | $981,950 |
2 | 4 | 1/1/2017 | $1,216,925 |
<tbody>
</tbody>