TerryHogarth21
Board Regular
- Joined
- Mar 20, 2012
- Messages
- 245
Bit stumped on this example below – was wondering if anyone has a workaround or easier way of doing this.
I have 2 tables in an Access DB
1 table entitled ‘Temp_Import’ that has 61fields (Invoice Date, Month 01, Month 02 all the way to Month 60) Yes this is not normalized, so I’m trying to do so.
In the second table entitled ‘Param_Tbl’ with 4 fields (Sequence_Num, Data_Type, Recognized_Month, Recognized_Year)
I have a select query that I can utilize to Insert in the first record for fields in the ‘Param_Tbl’
Basically in the temp table, the max month of invoice date +1 will be used unless it goes above 12 which then it would go back to month 1. The year would be the year of the max invoice date unless the month of the max invoice date +1 then it would be max year invoice date +1. The starting point is easy but the subsequent 59 is difficult.
<tbody>
</tbody>
I was thinking maybe just do a bunch of union’s from 1-60 but I am having trouble writing the logic sequentially. Last case result is to just write the formula in Excel and just import that as the table.
I have 2 tables in an Access DB
1 table entitled ‘Temp_Import’ that has 61fields (Invoice Date, Month 01, Month 02 all the way to Month 60) Yes this is not normalized, so I’m trying to do so.
In the second table entitled ‘Param_Tbl’ with 4 fields (Sequence_Num, Data_Type, Recognized_Month, Recognized_Year)
I have a select query that I can utilize to Insert in the first record for fields in the ‘Param_Tbl’
Code:
SELECT "Month 01 Recognized Amt" AS Type, IIf(MAX(MONTH([Temp_Import].[Invoice Date])+1)>12,1,MAX(MONTH([Temp_Import].[Invoice Date])+1)) AS Recognized_Month, IIf(MAX(MONTH(Temp_Import.[Invoice Date])+1)>12,MAX(Year(Temp_Import.[Invoice Date])+1),MAX(Year(Temp_Import.[Invoice Date]))) AS Recognized_Year
FROM Temp_Import;
Basically in the temp table, the max month of invoice date +1 will be used unless it goes above 12 which then it would go back to month 1. The year would be the year of the max invoice date unless the month of the max invoice date +1 then it would be max year invoice date +1. The starting point is easy but the subsequent 59 is difficult.
Param_Tbl | |||
---|---|---|---|
Data_Type | Recognized_Month | Recognized_Year | Sequence_Num |
Month 01 | 5 | 2015 | 1 |
Month 02 | 6 | 2015 | 2 |
Month 03 | 7 | 2015 | 3 |
Month 04 | 8 | 2015 | 4 |
Month 05 | 9 | 2015 | 5 |
Month 06 | 10 | 2015 | 6 |
Month 07 | 11 | 2015 | 7 |
Month 08 | 12 | 2015 | 8 |
Month 09 | 1 | 2016 | 9 |
Month 10 | 2 | 2016 | 10 |
<tbody>
</tbody>
I was thinking maybe just do a bunch of union’s from 1-60 but I am having trouble writing the logic sequentially. Last case result is to just write the formula in Excel and just import that as the table.