Hi,
I need to feed a complete Movements table from a fragmented one. In the complete Movements table I've a record for each year and month. In the fragemented table, from the OLTP system, I could have some combinations for year and month with no records.
In order to safeguard the performances, I think to run a first INSERT into complete Movements. Then, for each groups of data of the complete movements to get the last movement in order to assign the related data in the missing combinations of year and month, avoiding a loop if possible.
The following description says which result my proc should obtain:
Fragmented table
Mov_ID Mov_Type Mov_Center Mov_Date Year_Month
1 I C_001 17/01/2013 201301
2 M C_003 04/02/2013 201302
3 - - - 201303
4 - - - 201304
5 M C_005 - 201305
Completed table
Mov_ID Mov_Type Mov_Center Mov_Date Year_Month
1 I C_001 17/01/2013 201301
2 M C_003 04/02/2013 201302
3 M C_003 04/02/2013 201303
4 M C_003 04/02/2013 201304
5 M C_004 11/05/2013 201305
Any suggests to me, please?
Below a picture representation: