Based on Jan Nelson , we could add a quick check to return the original value if our index is not found.
DECLARE @email VARCHAR(100) SET @email = 'firstname.lastname.email.com/IMCLientName' SELECT CASE WHEN CHARINDEX('@',@email) > 0 THEN SUBSTRING(@email,0, CHARINDEX('@',@email)) ELSE @email END AS email
This will return 'firstname.lastname.email.com/IMCLientName'. If you used " firstname.lastname@email.com / IMCLientName", then you would get "firstname.lastname".
Izulien
source share