Sql Query to get domain Name from email column

The following T-SQL Query will retrieve anything that is after the @ symbol, the query can be very useful for retrieving the domain of an email address
SELECT SUBSTRING(T.Email,(CHARINDEX('@',T.Email)+1),LEN(T.Email) - (CHARINDEX('@',T.Email))) as DomainName FROM EmailTable T

Advertisement

3 Comments on “Sql Query to get domain Name from email column”

  1. sivareddy says:

    i need a query to get a name like below

    if email is friends@gmail.com

    the o/p will be like this:

    friends

    • Vamsi says:

      Try this query SELECT SUBSTRING(T.Email, 0, (CHARINDEX('@',T.Email)+1)) as EmailNamePart FROM EmailTable T

  2. sivareddy says:

    my email id is:sivareddy.mygo[at-the-rate]gmail.com


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.