I have a query performing poorly that joins two unindexed tables. Because I'm joining on telephone numbers coming from different sources, I'm using RIGHT() on the join conditions and doing some string manipulation through subqueries on each one of the tables. Would indexes help performance in this case? Example below
WITH ds_One AS (
SELECT REPLACE(PhoneNumber,'+44', '0') AS PhoneNumber
FROM PhoneNumbers
)
,ds_Two AS (
SELECT REPLACE(PhoneNumber,'+44', '0') AS PhoneNumber
,CustomerName
FROM PhoneNumbers2
)
SELECT two.CustomerName
FROM ds_Two two
INNER JOIN ds_One one
ON RIGHT(one.PhoneNumber,10) = RIGHT(two.PhoneNumber,10)