SQL Tips #13 - Finding the Domain from an Email Address


Wednesday, 10 May 2017

When you have a table of email addresses, it's sometimes useful to see the distinct domains they belong to.

The Query

SELECT distinct RIGHT(email, LEN(email) - CHARINDEX('@', email)) as domain 
FROM dbo.tblUsers
WHERE LEN(email) > 0

Disclaimer

These queries are provided as a guide, and are by no means perfect. I didn't write all of these - many are collated from MSDN documentation and community sources over the years.

Tags

SQL, Programming
Share with: 

Useful SQL tips - how to extract the distinct domain names from a column of email addresses


Support this Site

Buy me a coffee

Developer Courses

Pluralsight - Hardcore Developer and IT Training
Skype Web SDK: Getting Started
Skype Web SDK: Audio & Video

Popular Articles

What is Kutamo?
Kilimanjaro Climb
Kilimanjaro 2015
Kilimanjaro 2013
Australian Postcodes
New Zealand Postcodes
Worldwide City Database

Favourite Links

Kilimanjaro Climbs
Kutamo Studios
Kutamo Meetings
Litzi
ErrLog.IO
Kutamo

Tags / Keywords

SQL, Programming