What I'm trying to do is parse out a first and last name from an email address, separating them into first and last name fields in a view. I'm like 99% there but can't figure out what I am doing wrong.
The Last Name fields displays perfectly but the First Name displays as .John or .Dave. I know that represents one character off but if I try to subtract -1 from the second CHARINDEX I get an error.
A sample email address is John.Smith@anything.com.
The Last Name fields displays perfectly but the First Name displays as .John or .Dave. I know that represents one character off but if I try to subtract -1 from the second CHARINDEX I get an error.
A sample email address is John.Smith@anything.com.
Code:
SELECT Email, SUBSTRING(Email, 0, CHARINDEX('.', Email)) AS [Last Name], SUBSTRING(Email, CHARINDEX('.', Email), CHARINDEX('@', Email)
- CHARINDEX('.', Email)) AS [First Name]
FROM dbo.tblUndeliverableEmails