Are you running ALL 3 of those at the same time or just selecting one and then running it and selecting another and running it, etc.?
ALL 3, you mean the renewals ?
No, not running 3 at the same time, not even selecting another and running it.
Here's the logic:
- user selects renewal 1 and the language of its choice
-data is moved to table Tb_1stRenewalTMP
-at the same time, another query moves data to Tb_data which is another table
-merge data from Tb_1stRenewalTMP into Word
-empty table Tb_1stRenewalTMP
If user want to run second renewal, it cannot be run on the same day like the 1st renewal. So if the 1st renewal was run today and tomorrow user will only run the second renewal, then
-data is moved to Tb_2ndRenewalTMP but query will not look in the ASSURVAR1 table, but in the Tb_data. Why ? Table tb_data contains the same fields as the 3 tables (Tb_1stREnewalTMP, etc), but it also contain an additional field, field Dt_renewal. It's a date field with todays date.
In other words, when user executed the query for the 1st renewal, same data was moved to table Tb_data and stamped with todays date.
So for the second query, the query will look into Tb_data and move records to table Tb_2nd renewal.
Same logic applies for 3rd renewal.
you can't run both on the same day. 1st renewal is the first as it select records in the past 30 days, moves them to Tb_data. Then 2st renewal which look for records in the past 15 days will look in the table Tb_data because it needs to use the EXP_DATE field and the field date_renewal so it can determine which records needs to be moved to Tb_2ndRenewalTMP.
i hope you understand better now.
Thanks