Hi, you can even try with the following too
Declare @str varchar(50) = 'sample@gmail.com'
Solution 1
Select
Name = Left(@str, PATINDEX('%@%',@str)-1)
,Domain = Right(@str,Len(@str)-PATINDEX('%@%',@str))
,Email = @str
Solution 2
Select
Name = Left(@str, CHARINDEX('@',@str)-1)
,Domain = Right(@str,Len(@str)-CHARINDEX('@',@str))
,Email = @str
Solution 3
Select
Name = REVERSE(STUFF(REVERSE(@str),1,PATINDEX('%@%',REVERSE(@str)),''))
,Domain = STUFF(@str,1,PATINDEX('%@%',@str),'')
,Email = @str
In all the three cases the answer will be
Name Domain Email
sample gmail.com sample@gmail.com
Hope this helps
Best Regards,
Niladri Biswas
Gopal_nivas, if this helps please login to Mark As Answer. | Alert Moderator