>>I suggest to re-write this statement.
>>
>>1. Start from a select statement to return what you will need.
>>
>>2. Once you get your select statement working properly, turn it into MERGE command.
>
>The original select was what I needed. I only needed to add a condition in the WHERE clause to use one way or another based on the fact that if there is a company or not. The default, is to use the province from the Company table, if we have a Client.NoCompany. Otherwise, we use the province from the Research table, if we have Client.NoCompany=0 and a Client.NoResearch>0.
So, how long does the select with the changed condition executes?
Also, for that particular part I suggest to re-write into union all based on that condition.
If it's not broken, fix it until it is.
My Blog