by

Retrieve the domain of an email in MS SQL Server

Suppose you have a table with an 'Email' field: here is the way to retrieve just only the domain of that email, and the name of the domain without the extension (.com, .net, etc.)
Copy Embed Code
<iframe id="embedFrame" style="width:600px; height:300px;"
src="https://www.snip2code.com/Embed/232111/Retrieve-the-domain-of-an-email-in-MS-SQ?startLine=0"></iframe>
Click on the embed code to copy it into your clipboard Width Height
Leave empty to retrieve all the content Start End
select SUBSTRING(Email, charindex('@', Email, 0) + 1, (charindex('.', Email, charindex('@', Email, 0)) - charindex('@', Email, 0)) - 1 ) as domainWithNoExt, SUBSTRING(Email, charindex('@', Email, 0) + 1, 200) as domain from MyTable
If you want to be updated about similar snippets, Sign in and follow our Channels

blog comments powered by Disqus