Storing the list of email subscribers is quite often seen in the web based companies. Once the emails are stored they are segmented based on the customer interests and products they have purchased on the website.
In this article I will show the simple step of extracting the Account Name and Domain Name using T-sql.
DECLARE @email NVARCHAR(MAX)
DECLARE @EmailAccount NVARCHAR(100)
DECLARE @EmailDomain NVARCHAR(100)
SET @email = ‘george@yahoo.com’
SET @EmailAccount = Lower(LTrim(Substring(@Email, 1, Charindex(‘@’,@Email, 1) – 1)))
SET @EmailDomain = Lower(RTrim(Substring(@Email, Charindex(‘@’,@Email, 1) + 1, 1000)))
PRINT @EmailAccount
PRINT @EmailDomain


Nice… really useful, thxs.