Two Ways to Clean Email from ERP Database

I recently worked with some data from an ERP which stored customer’s email addresses like so: customer@company.com#customer@company.com.
Goofy right. Anyway, here are a couple of methods of cleaning up the data and returning only the first part of such a string.

STUFF(b.Email, PATINDEX('%#%', b.Email), ( LEN(b.Email) - PATINDEX('%#%', b.Email) + 1 ), '') 'Email2'
SUBSTRING( b.Email, 1, PATINDEX('%#%', b.Email) - 1 ) 'Email3'

Leave a Reply

Your email address will not be published. Required fields are marked *