Perhaps the following TSQL code can help you:
DECLARE @email varchar(200)
SELECT @email = 'John Doe [email protected]'
SELECT REVERSE(SUBSTRING(REVERSE(@email), 0,CHARINDEX(' ', REVERSE(@email))))
That statement returns:
[email protected]
Talking through the logic:
- Reverse the email column
- Find the index of the first ' ' character ... everything up to this point is your actual email address
- Substring the column, from the start of the (reversed) string, to the index found at step 2.
- Reverse the string again, putting it in the right order.
There might be more elegant ways of doing it, but that would work, and you could therefore use it for one side of your JOIN.
It works because email addresses cannot contain spaces, so therefore the last space (or first when you reverse it) will be the separator between your actual email address, and friendly one.
As far as I know TSQL does not contain a LastIndexOf() function, which would have been handy to avoid the double Reverse() function calls.