sql server - How to TRIM email in MSQL to only leave domain without duplicates (Only 1 domain) -


i have email column in msql server , need trim emails leave domains. on left side of @ including "@" needs go away. @ same time need 1 domain no duplicates..

example:

column name = domains  test@example.com test2@example.net test3@example.com          .          .          . 

------- -> -------

column name = domains  example.com example.net 

declare @foo table (foo varchar(100)); insert @foo values ('test@testcompany.com'), ('test2@testcompany2.com'), ('test3@testcompany.com')  --fun version select distinct     parsename(replace(foo, '@', '.'), 2) + '.' + parsename(foo, 1)     @foo  --deals more 3 dots --8000 allows *not* know actual string length. "just works" select distinct     substring(foo, charindex('@', foo)+1, 8000)     @foo 

Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

Add new key value to json node in java -