Question : Please increase performance of this extremely slow sql statement

Hi Experts,

I have a sql statement which is extremely slow.
I know, the reason are the two joins. But I don't know how to increase the performance.
Please help with reconstructing this statement.
Thanks a lot
Code Snippet:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
Select 
coalesce(T2.Salesperson_Code, 'BLANK') AS Salesperson_Code, 
coalesce(T2.Company + '-' + T2.Salesperson_Code, T2.Company+'_BLANK') AS Salesperson_ID, 
coalesce(T3.Description, 'Area not defined') AS [Area Description], 
coalesce(T3.Code, T2.[Company]+'_BLANK') AS [Area Code], RTRIM(LTRIM(T3.Code)) + ' / ' + T3.Description AS Area, 

coalesce(T2.Salesperson_Code_2, 'BLANK') AS Salesperson_Code_2, 
coalesce(T2.Company + '-' + T2.Salesperson_Code_2, T2.Company+'_BLANK') AS Salesperson_2_ID,
coalesce(T4.Description, 'Area not defined') AS [Area2 Description],
coalesce(T4.Code, T2.[Company]+'_BLANK') AS [Area2 Code], RTRIM(LTRIM(T4.Code)) + ' / ' + T4.Description AS Area2, 
T2.Company AS Company, T2.Name As [Customer Name], RTRIM(LTRIM(T2.No_)) + ' / ' + T2.Name As [Customer Description] 

FROM 
       
[05_Customer] AS T2 LEFT OUTER JOIN
	VW_Sales_Area_Force_0 AS T3 ON T2.Salesperson_Code = T3.Salesperson_Code AND T2.Company = T3.Company,
[05_Customer] AS T5 LEFT OUTER JOIN
	VW_Sales_Area_Force_1 AS T4 ON T5.Salesperson_Code = T4.Salesperson_Code AND T5.Company = T4.Company

Answer : Please increase performance of this extremely slow sql statement

Why is there a T5 in your FROM-clause?  I don't see where it is used in the query.

Do you have indexes on the fields [Salesperson_Code] and [Company] in the [05_Customer] table?  That is probably the first thing you should look at.

HTH,

Joris
Random Solutions  
 
programming4us programming4us